below is my code that is not executing successfully. Any suggestions would be greatly appreciated. I am unable to troubleshoot, I am wondering if it is just placement?
This is the error message I receive:
Msg 8120, Level 16, State 1, Line 7 Column 'prod.dbo.prov_fee_schedule.FEE_PROV' is invalid in the select >list because it is not contained in either an aggregate function or the GROUP BY clause.
Here is my code:
SELECT *
FROM nwh_analytics.dbo.km_cmr_table a
LEFT JOIN (SELECT CASE
WHEN location IN ( '03', '05', '11', '12',
'15', '20', '25', '32',
'41', '42', '49', '50',
'60', '71', '72', '81', '99' )
THEN
'Non Facility'
WHEN location = '*' THEN 'Facility'
ELSE 'error'
END AS LOC,
fee_prov,
fee_cpt,
cpt_modifier,
rate_a,
rate_b,
rate_c,
pct
FROM prod.dbo.prov_fee_schedule
WHERE to_date >= '2017-01-01'
AND fee_prov IN ( 'TUPP00' )
GROUP BY CASE
WHEN location IN ( '03', '05', '11', '12',
'15', '20', '25', '32',
'41', '42', '49', '50',
'60', '71', '72', '81', '99' )
THEN
'Non Facility'
WHEN location = '*' THEN 'Facility'
ELSE 'error'
END) b
ON a.code = b.fee_cpt