Save Procedure Select a Variable

How can I calculate the result of a table and go into a stored procedure variable?

DECLARE @totalrecs varchar select count(id) from table1 

I need a count entry in the variable totalrecs.

+7
sql sql-server stored-procedures
source share
3 answers

like this

 --will not count NULLS select @totalrecs= count(id) from table1 --will count NULLS select @totalrecs= count(*) from table1 
+12
source share
 DECLARE @totalCount Int Select @totalCount = count(*) From table1 Exec sp_DoSomething @Var = @totalCount 
+2
source share
 select @totalrecs= count(id) from table1 
+1
source share

All Articles