Reputation: 1599
I need to get a column value from a table on SQL server 2008.
DECLARE @result TABLE
(
val FLOAT
);
insert into @result (val)
(
select SUM(c)/10 val from atable
)
DECLARE @myval float
SELECT @myval = @result.val # error : Must declare the scalar variable "@result". !!!
if @myval = null
begin
select @myval
end
Why ?
thx !
Upvotes: 0
Views: 364
Reputation: 39777
The correct format is
SELECT @myval = val FROM @result
But I think creating a table is an overkill here. You can do simple
select @myval = SUM(c)/10 from atable
If I understend you correctly.
Or if you simple return result of the sum, just do
select SUM(c)/10 from atable
to get the result back to the caller without any additional perturbations.
Upvotes: 1