My stored procedure (SQL Server 2005) returns a dataset where one field depends, among other things, on the number of rows returned by the query. I can make a simplified first query that allows me to get @@ROWCOUNT but, in that case, the procedure returns the two sets, which is not what I want.
I tried putting the first query in a WITH statement but haven’t found the syntax to extract the row count and put it in a variable that I could use in the second query. An alternative would be to get @@ROWCOUNT from the first query and tell the procedure to return only the result of the second query.
There are probably better ways to do that but my expertise in SQL is quite limited…
Thanks for any help!
Is this what you’re looking for? If not, could you please describe your problem in more details (perhaps, with code snippets)