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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2003-06-02 : 08:06:55
|
| savitha nair writes "I have a dynamic query, in my stored procedure that returns the total no. of records, matching a given criteria. Based on the count of records returned from this dynamic query, the rest of the stored procedure is supposed to get executed.Though the dynamic SQL works fine and returns the correct no. of records, Iam not able to use the result to proceed with the stored procedure.How do I retrieve the result of my SQL dynamic query in a variable?" |
|
|
SamC
White Water Yakist
3467 Posts |
Posted - 2003-06-02 : 08:30:46
|
| Depends on how you are returning the result.Look up articles on "output variables" see: [url]http://sqlteam.com/item.asp?ItemID=2644[/url]on SQLTEAM's homepage. But if you are returning the rows in a recordset, then it's another matter. Use @@ROWCOUNT to get the number of records in this case.On the other hand, if you are returning COUNT(*) as a column in a single row recordset, then you have a problem.The following solution doesn't return a recordset, just the countDECLARE @Mycount INTSELECT @Mycount = COUNT(*) FROM MyTable WHERE my-conditionSam |
 |
|
|
|
|
|