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
The Output Parameters in Stored Procedures are used to return some value or values. A Stored Procedure can have any number of output parameters. The simple logic is this — If you want to return 1 value then use 1 output parameter, for returning 5 values use 5 output parameters, for 10 use 10, and so on.
Output parameter is a parameter whose value is passed out of the stored procedure/function module, back to the calling PL/SQL block. An OUT parameter must be a variable, not a constant. It can be found only on the left-hand side of an assignment in the module.
Variables in SQL procedures are defined by using the DECLARE statement. Values can be assigned to variables using the SET statement or the SELECT INTO statement or as a default value when the variable is declared. Literals, expressions, the result of a query, and special register values can be assigned to variables.
Try this way:
SELECT @Counter = COUNT(*)
FROM #tmpUsers
or
SET @Counter = (SELECT COUNT(*) FROM #tmpUsers)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With