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
 SQL Server Development (2000)
 Assign Dynamic SQL result to local variable

Author  Topic 

beyonder422
Posting Yak Master

124 Posts

Posted - 2005-12-08 : 16:56:01
I want to run a dynamic SQL statement within a proc and have it's result set to a @local variable within that same proc, like below:

declare @sql nvarchar (1000),
@test varchar(100)

set @sql = 'select top 1 xyz from xzy'
set @test = (EXEC sp_executesql @SQL)
select @test

Is this possible?

www.beyonder422.com

beyonder422
Posting Yak Master

124 Posts

Posted - 2005-12-08 : 18:22:05
answered my own question:

exec sp_executesql @sql,
N'@build_count nvarchar(5) OUTPUT',
@build_count OUTPUT

www.beyonder422.com
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-12-09 : 00:33:59
Also
http://www.mindsdoor.net/SQLTsql/sp_executeSQL.html

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -