变量中的select语句获取了多少条记录?

How many records were obtained from the select statement in a variable?

我在存储过程中使用这段代码。 我想将 return value select 语句插入到这样的变量中:

declare @count int
set @count = select count(*) from table_name

可能吗? 请帮助

如果用括号括起来就是了。

declare @count int
set @count = (select count(*) from table_name)

但是只

更简单
declare @count int
select @count = count(*) from table_name

这适用于 SQL 服务器。 YMMV