Package cursor storage process (PR

xiaoxiao2021-03-06  71

Using the script you can perform your own feature, the package cursor operation stored procedure is as follows: Create Procedure PR_EXECSQL2 @asqlstring varchar (8000) - Enter SQL Statement AS EXEC ('- Start Transaction 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 @ASqlEXEC (@ASql) IF @@ ERROR <> 0 goto finalexit fetch next from tnames_cursor @ASQL END Close TNames_Cursor Deallocate TNames_Cursor

Commit Tran Return

Finalexit: Rollback Tran Close TNames_Cursor Deallocate TNames_Cursor

') How to use: declare @SQL varchar (8000) set @ SQL =' SELECT '' UPDATE A SET A.A = ' B.A from b' EXEC PR_EXECSQL2 @SQL

转载请注明原文地址:https://www.9cbs.com/read-93676.html

New Post(0)