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)
 dynamic sql and local variable assignment

Author  Topic 

bigwhacker
Starting Member

6 Posts

Posted - 2004-08-18 : 12:38:08

I need to perform the following - but ...
@lastupdtime = exec ("SELECT LASTUPDDTTM FROM " + @DBName + "..PSSERVERSTAT WHERE SERVERNAME = 'PSNT'")

How can I get a local variable assignment from dynamic sql?

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-08-18 : 12:53:30
you can't this way. you can write a stored procedure or use a global temp table (##temp)

Go with the flow & have fun! Else fight the flow :)
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-08-18 : 13:15:22
oh yeah i forgot: you can also do this:

declare @stmt nvarchar(100)
declare@lastupdtime int
set @stmt = 'SELECT LASTUPDDTTM FROM " + @DBName + "..PSSERVERSTAT WHERE SERVERNAME = \'PSNT\''
exec @lastupdtime = sp_executesql @stmt



Go with the flow & have fun! Else fight the flow :)
Go to Top of Page
   

- Advertisement -