sql - 将过程选择存储到变量中

标签 sql sql-server stored-procedures

如何计算表的结果并将其传递到存储过程变量?

DECLARE @totalrecs varchar
select count(id) from table1

我想要totalrecs变量中的计数记录。

最佳答案

像这样

--will not count NULLS
select @totalrecs= count(id) from table1

--will count NULLS
select @totalrecs= count(*) from table1

关于sql - 将过程选择存储到变量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2353302/

相关文章:

mysql - 在 WHERE 子句中使用子查询结果

sql - Postgresql,具有多个键的 jsonb 为每个键返回一行

SQL Server : how to transpose rows into columns

sql - 在存储过程中如何运行查询并有条件地做某事

c# - 在存储过程调用中使用默认参数

用于获取表名、 View 和存储过程的 SQL 语句,按模式排序

php - 更改 WordPress SQL 数据库以自定义帖子类型

SQL多列分组在一行中

sql-server - 复合增量列

mySql 过程条件未发生