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
 General SQL Server Forums
 New to SQL Server Programming
 Saving value returned by Select in variable

Author  Topic 

SQLUSERNAME
Starting Member

4 Posts

Posted - 2007-07-16 : 16:02:05
What is the syntax for saving a single value returned by a Select statement in a variable? I have tried the following, but its telling me I "Must declare the variable '@TempCount'." which is already declared!


SET @SQL = 'Select @TempCount = count(*) FROM ' + @TblName + ' WHERE ' + .......
exec(@SQL)

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-07-16 : 16:08:32
What you are asking is similar to this post here. http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=86441

Create a temp table, insert the value into it and query from it later.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page
   

- Advertisement -