Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Set Variable to result of Dynamic SQL?

Author  Topic 

cosmo
Starting Member

2 Posts

Posted - 2004-01-15 : 23:42:16
Is there a way to set a variable to the result of a dynamic sql statement?

Example:

DECLARE
@aSQL NVARCHAR(250),
@aCount INT

SELECT @aSQL = 'SELECT COUNT(*) FROM [System]'

--EXEC sp_ExecuteSQL @aSQL

SELECT @aCount = EXEC sp_ExecuteSQL @aSQL

Thanks for your time!

nr
SQLTeam MVY

12543 Posts

Posted - 2004-01-16 : 01:13:12
see
http://www.nigelrivett.net/sp_executeSQL.html


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

cosmo
Starting Member

2 Posts

Posted - 2004-01-19 : 16:34:29
Thanks nr!
Go to Top of Page
   

- Advertisement -