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.
| Author |
Topic |
|
pharvey
Starting Member
20 Posts |
Posted - 2006-02-09 : 08:33:29
|
| Hi everybody!I would like to know how to put the result of a querry in a variable. By example i have this variable:DECLARE @NbUser intI would like to put the result of this querry on this variable:SELECT COUNT(UserID) FROM tblUserSuppose the querry return 23, i want to put this 23 on the variable.I need it to do some other operation after. I'm using stored procedure.Anyone can help?Thank you!Pascal |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-02-09 : 08:34:50
|
| [code]SELECT @NbUser = COUNT(UserID) FROM tblUser[/code]----------------------------------'KH'everything that has a beginning has an end |
 |
|
|
pharvey
Starting Member
20 Posts |
Posted - 2006-02-09 : 08:40:16
|
| Thank you khtan!Pascal |
 |
|
|
pharvey
Starting Member
20 Posts |
Posted - 2006-02-09 : 08:52:23
|
| A little bit more complex now.I want to retrieve it from a querry like that:select @vSQL = 'SELECT COUNT(tp.[ID]) FROM tblPhoto tp 'select @vSQL = @vSQL + 'LEFT JOIN tblPhotoImages AS tpi ON tpi.PhotoID = tp.[ID] 'select @vSQL = @vSQL + 'LEFT JOIN tblImages AS ti ON ti.[ID] = tpi.ImageID 'IF @CategoryID > 0 BEGIN select @vSQL = @vSQL + ' WHERE tp.CategoryID = ' + convert(varchar, @CategoryID)ENDExecute(@vSQL)How can i put it on the variable with an Execute behind it.Pascal |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-02-09 : 08:59:03
|
| use sp_executesql. It allow passing of parameter----------------------------------'KH'everything that has a beginning has an end |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|