Using Subquery inside STRING_AGG

Viewed 76

I am having trouble with the following SQL Server code, keep getting this error:

Application Error Occurred: Cannot perform an aggregate function on an expression containing an aggregate or a subquery.

  SELECT brand_name,
     STRING_AGG('    ' +    (SELECT model_year  FROM production.products    WHERE model_year > 2001 )
     + ',    ' + ISNULL(list_price,'') 
     + ',    ' +    (SELECT model_price FROM production.products    WHERE model_price > 50  )       
            ,',')   within GROUP (order by  1) Tuition
  FROM production.brands  
0 Answers
Related