Reputation: 1871
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.
Upvotes: 10
Views: 40223
Reputation: 1837
DECLARE @totalCount Int
Select @totalCount = count(*)
From table1
Exec sp_DoSomething @Var = @totalCount
Upvotes: 2
Reputation: 134933
like this
--will not count NULLS
select @totalrecs= count(id) from table1
--will count NULLS
select @totalrecs= count(*) from table1
Upvotes: 17