Friday, March 27, 2015

Assigning avg to columns and grouping that info by date

Hi ojmp2001,



Regarding your original post, it seems you have some misunderstanding on the scalar variable in T-SQL. As per the BOL:Transact-SQL Variables.



  • A variable can also have a value assigned by being referenced in a select list. If a variable is referenced in a select list, it should be assigned a scalar value or the SELECT statement should only return one row.

  • If a SELECT statement returns more than one row and the variable references a nonscalar expression, the variable is set to the value returned for the expression in the last row of the result set .


So your query is expected to return only one row.



To achieve your requirement, you can reference Partrick's.



If you have any feedback on our support, you can click here.




Eric Zhang

TechNet Community Support




No comments:

Post a Comment