Win
Win

Reputation: 2613

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

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

Is it possible to assign the value of

SELECT COUNT(*) FROM #tmpUsers

To the @Counter output parameter?

I have tried

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

But this doesn't work for me

Upvotes: 5

Views: 4880

Answers (1)

Robert
Robert

Reputation: 25753

Try this way:

SELECT @Counter = COUNT(*) 
FROM #tmpUsers

or

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

Upvotes: 14

Related Questions