In my SP, the following syntax checks as successful. When I add a Group By clause, I get Error 8120 which tells me that several of my fields are "invalid in the select list" because they are "not contained in either an aggregate function or the GROUP BY clause." Same this happens when I run it in Query Analyzer. Can anyone help me understand this?
select distinct
@session,a.product_catalog_id,b.division,b.division_department,b.division_class,b.division_manufacturer,
h.storename,f.ccnname,b.style,a.style_description,c.color_no,e.name,a.uglc,c.ad_sample,d.mu_percent,
MU_PERCENT_pct = (a.owned_retaila.uglc)/a.owned_retail*100,a.owned_retail,0
from
mp..style a, mp..otb_header b, mp..otb_detail c, mp..price_level d, cas..cas_mcolor e, reftables..ccntable f, reftables..sizepack g,
reftables..stores h
WHERE a.product_catalog_id = @product_catalog_id and
a.product_catalog_id = b.product_catalog_id and
a.style = b.style and
a.style = c.style and
b.division = h.store and
b.division = @Division and
f.ccn = substring(@product_catalog_id,1,3)
select distinct
@session,a.product_catalog_id,b.division,b.division_department,b.division_class,b.division_manufacturer,
h.storename,f.ccnname,b.style,a.style_description,c.color_no,e.name,a.uglc,c.ad_sample,d.mu_percent,
MU_PERCENT_pct = (a.owned_retaila.uglc)/a.owned_retail*100,a.owned_retail,0
from
mp..style a, mp..otb_header b, mp..otb_detail c, mp..price_level d, cas..cas_mcolor e, reftables..ccntable f, reftables..sizepack g,
reftables..stores h
WHERE a.product_catalog_id = @product_catalog_id and
a.product_catalog_id = b.product_catalog_id and
a.style = b.style and
a.style = c.style and
b.division = h.store and
b.division = @Division and
f.ccn = substring(@product_catalog_id,1,3)