开发者

How can I get the number of rows in dynamic query's result?

开发者 https://www.devze.com 2023-03-22 02:55 出处:网络
I have created one dynamic query and it all works well. I execute the query usin开发者_Go百科g: EXEC sp_executesql @SQLQuery

I have created one dynamic query and it all works well. I execute the query usin开发者_Go百科g:

EXEC sp_executesql @SQLQuery

where @SQLQuery is one dynamic query.

My only question is how can I also return the number of rows present after the execution of this query? I hope my question is clear.

Thanks in advance:)


You can use the @@rowcount which will return you the last query effected row count.

EXEC sp_executesql @SQLQuery

DECLARE @rowcount int
SET @rowcount = @@rowcount
SELECT @rowcount as NumofRows


use the count() function of SQL EXEC sp_executesql @SQLQuery

DECLARE @rownum as int
SET @rownum = (SELECT count([column]) from [tablename])
0

精彩评论

暂无评论...
验证码 换一张
取 消