存储过程选择变量

时间:2010-03-01 00:51:37

标签: sql sql-server stored-procedures

如何计算表的结果并传入存储过程变量?

DECLARE @totalrecs varchar
select count(id) from table1

我想在totalrecs变量中记录计数记录。

3 个答案:

答案 0 :(得分:14)

像这样

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

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

答案 1 :(得分:2)


DECLARE @totalCount Int
Select @totalCount = count(*) 
From table1

Exec sp_DoSomething @Var = @totalCount

答案 2 :(得分:1)

select @totalrecs= count(id) from table1