Setting the output parameter to count () in the sql stored procedure

I have an output parameter @Counter and a temporary table #tmpUsers

Is it possible to assign a value

 SELECT COUNT(*) FROM #tmpUsers 

To the output parameter of @Counter ?

I tried

 SET @Counter = SELECT COUNT(*) FROM #tmpUsers 

But this does not work for me

+4
source share
1 answer

Try as follows:

 SELECT @Counter = COUNT(*) FROM #tmpUsers 

or

 SET @Counter = (SELECT COUNT(*) FROM #tmpUsers) 
+12
source

Source: https://habr.com/ru/post/1495506/


All Articles