开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜