How can I count the result of a table and pass into a Stored Procedure Variable?
如何计算表的结果并传入存储过程变量?
DECLARE @totalrecs varchar
select count(id) from table1
I want the count record in the totalrecs variable.
我想要totalrecs变量中的计数记录。
3 个解决方案
#1
13
like this
喜欢这个
--will not count NULLS
select @totalrecs= count(id) from table1
--will count NULLS
select @totalrecs= count(*) from table1
#2
2
DECLARE @totalCount Int
Select @totalCount = count(*)
From table1
Exec sp_DoSomething @Var = @totalCount
#3
1
select @totalrecs= count(id) from table1
#1
13
like this
喜欢这个
--will not count NULLS
select @totalrecs= count(id) from table1
--will count NULLS
select @totalrecs= count(*) from table1
#2
2
DECLARE @totalCount Int
Select @totalCount = count(*)
From table1
Exec sp_DoSomething @Var = @totalCount
#3
1
select @totalrecs= count(id) from table1