Search
 
SCRIPT & CODE EXAMPLE
 

SQL

sql transact create cursor with dynamic tables

Declare @UserID varchar(100)
declare @sqlstatement nvarchar(4000)
--move declare cursor into sql to be executed
set @sqlstatement = 'Declare  users_cursor CURSOR FOR SELECT userId FROM users'

exec sp_executesql @sqlstatement


OPEN users_cursor
FETCH NEXT FROM users_cursor
INTO @UserId

WHILE @@FETCH_STATUS = 0
BEGIN
Print @UserID
EXEC asp_DoSomethingStoredProc @UserId

FETCH NEXT FROM users_cursor --have to fetch again within loop
INTO @UserId

END
CLOSE users_cursor
DEALLOCATE users_cursor
Comment

PREVIOUS NEXT
Code Example
Sql :: TSQL Code Snippet For Optimized Sales Query 
Sql :: dynamic pivot 
Sql :: ring MySQL get the result data without columns names 
Sql :: SQL RIGHT JOIN With AS Alias 
Sql :: suhaib 
Sql :: odoo there is no primary key for referenced table "res_users" 
Sql :: Convert LDAP Epoch to Date 
Sql :: mamp mysql config file 
Sql :: sparql comment multiline 
Sql :: sqlite table headers 
Sql :: Fatal error: Uncaught mysqli_sql_exception: Unknown or incorrect time zone 
Sql :: sql find column with trailing space 
Sql :: hoq to import database source 
Sql :: supabase change timezozne 
Sql :: Sauvegarde complète my sql 
Sql :: mysqlcli how to load external sql file 
Sql :: oracle pl/sql check if file exists 
Sql :: Resulting Query 
Sql :: mysql procedure between two tables 
Sql :: get item by composite primary key mysql 
Sql :: postgres audit table 
Sql :: create bakupd database sqlserver 
Sql :: MySQL can’t specify target table for update in FROM clause (Updating same table from same select inner join table) 
Sql :: how to install firebird 
Sql :: how to connect pgadmin with excel 
Sql :: show specific partition hive query 
Sql :: avoid duplicate in one to many relationship join in sql 
Sql :: closure in sql 
Sql :: create table using the clause with as 
Sql :: sql developer format sql 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =