Home:ALL Converter>get a column value from a table and assign it ot a scalar variable on SQL server 2008

get a column value from a table and assign it ot a scalar variable on SQL server 2008

Ask Time:2014-05-24T07:58:41         Author:user3448011

Json Formatter

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 !

Author:user3448011,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/23839913/get-a-column-value-from-a-table-and-assign-it-ot-a-scalar-variable-on-sql-server
yy