I have a query in stored in a variable @query

I execute that query using following statement

execute(@query)

I want the number of rows returned by executing above statement in sql server

How can i get that?

This should to the trick:

select @@rowcount

Just make sure you do it as the VERY NEXT statement... @@rowcount gets set after every SQL statement that returns results.

You can also set a local variable equal to the results:

declare @myVar int
select @myVar = @@rowcount

Hope this helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.