iosdevnyc
iosdevnyc

Reputation: 1871

Store Procedure Select into a variable

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

Answers (3)

Leigh S
Leigh S

Reputation: 1837


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

Exec sp_DoSomething @Var = @totalCount

Upvotes: 2

SQLMenace
SQLMenace

Reputation: 134933

like this

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

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

Upvotes: 17

Rockcoder
Rockcoder

Reputation: 8479

select @totalrecs= count(id) from table1

Upvotes: 1

Related Questions