Reputation: 5941
How can I set result from with query into variable?
I have variable
declare @ResultVar float;
and with query
WITH CTE AS
(
SELECT [Val]...
)
SELECT SUM([Val])
FROM CTE
I don't want to use SELECT
, this is part of a SQL Server stored procedure.
Upvotes: 0
Views: 738
Reputation: 238086
Per @marc_s's comment:
WITH CTE AS
(
SELECT [Val]...
)
SELECT @YourVar = SUM([Val])
FROM CTE
A select
that assigns a variable does not return a rowset to the caller of the stored procedure. Try it.
Upvotes: 3