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)
 EXEC Statement Query !!!

Author  Topic 

nishithrn
Yak Posting Veteran

58 Posts

Posted - 2003-01-06 : 09:11:34
Hi

How do I get the output of an exec statement into a variably..??

I am using the following query...

declare @dbsize int
declare @dbname char (10)
declare @sqlcmd varchar(55)
set @dbname = 'master'
print @dbname
select @sqlcmd = 'select size from '+@dbname+'.dbo.sysfiles where fileid=1'
exec (@sqlcmd)

Now, I want to assign the output of the above into a variable. Pls. help.

Thanks in advance
Nishith

Onamuji
Aged Yak Warrior

504 Posts

Posted - 2003-01-06 : 09:17:22
Reference: sp_executesql

DECLARE @sql NVARCHAR(4000), @size INT, @db NVARCHAR(128)

SET @db = N'master'
SET @sql = N'SELECT @size=size FROM [' + @db + '].dbo.sysfiles WHERE fileid = 1'

EXEC sp_executesql @sql, N'@size INT OUTPUT', @size OUTPUT

PRINT @size

Go to Top of Page

nishithrn
Yak Posting Veteran

58 Posts

Posted - 2003-01-07 : 01:08:17
It works, tx a mil for ur Help Onamuji

Go to Top of Page
   

- Advertisement -