时间:2021-07-01 10:21:17 帮助过:38人阅读
BEGIN TRAN
DECLARE @ASql VARCHAR(8000)
DECLARE tnames_cursor CURSOR LOCAL FAST_FORWARD FOR '+ @asqlstring +'
OPEN tnames_cursor
FETCH NEXT FROM tnames_cursor INTO @ASql
WHILE (@@FETCH_STATUS=0)
BEGIN
print @ASql
EXEC (@ASql)
IF @@ERROR <> 0 GOTO FINALEX99v
FETCH NEXT FROM tnames_cursor INTO @ASql
END
CLOSE tnames_cursor
DEALLOCATE tnames_cursor
COMM99v TRAN
RETURN
FINALEX99v:
ROLLBACK TRAN
CLOSE tnames_cursor
DEALLOCATE tnames_cursor
')
使用方法:
declare @sql varchar(8000)
set @sql='select ''update a set a.a='' + b.a from b '
exec Pr_execsql2 @sql