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)
 sp_executesql

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-06-03 : 08:29:21
Karsten writes "Hi,
why does this not work?

declare @i int
exec sp_executesql N'select count(*) from master.dbo.spt_values where type = ''C''', N'@i int output', @i output
select @i

I would like to get the result into the var @i, but I always just get null.

What is the mistake?

Thanks in advance
Karsten"

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2003-06-03 : 11:45:07
Why not just do :


Declare @i int
Select @i = count(*) from master.dbo.spt_values where type='c'
Select @i




?????


Damian

Edited by - merkin on 06/03/2003 11:45:57
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2003-06-03 : 13:38:48
But the problem with your code is that you aren't assigning the value to the variable

declare @i int
exec sp_executesql N'select @i = count(*) from master.dbo.spt_values where type = ''C''', N'@i int output', @i output
select @i

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
   

- Advertisement -