I have created one dynamic query and it all works well. I execute the query using:
我创建了一个动态查询,它运行良好。我使用以下方式执行查询:
EXEC sp_executesql @SQLQuery
where @SQLQuery is one dynamic query.
@SQLQuery是一个动态查询。
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:)
提前谢谢:)
2 个解决方案
#1
5
You can use the @@rowcount
which will return you the last query effected row count.
您可以使用@@rowcount返回最后一个查询影响的行计数。
EXEC sp_executesql @SQLQuery
DECLARE @rowcount int
SET @rowcount = @@rowcount
SELECT @rowcount as NumofRows
#2
-1
use the count() function of SQL EXEC sp_executesql @SQLQuery
使用SQL EXEC sp_executesql @SQLQuery的count()函数
DECLARE @rownum as int
SET @rownum = (SELECT count([column]) from [tablename])
#1
5
You can use the @@rowcount
which will return you the last query effected row count.
您可以使用@@rowcount返回最后一个查询影响的行计数。
EXEC sp_executesql @SQLQuery
DECLARE @rowcount int
SET @rowcount = @@rowcount
SELECT @rowcount as NumofRows
#2
-1
use the count() function of SQL EXEC sp_executesql @SQLQuery
使用SQL EXEC sp_executesql @SQLQuery的count()函数
DECLARE @rownum as int
SET @rownum = (SELECT count([column]) from [tablename])