I have a sql script that loads data for reporting. I would like to alias the data in one of the fields so that the output is slightly different. if I do not use the field below (in blue) the data loads perfectly. What am I doing incorrectly here?
SQL SELECT DISTINCT substr(PAIDDATE,1,6), PAIDMONTH, COUNTYCODE = CASE WHEN A.GROUPCODE='HCBUC' THEN 'BUCKS' WHEN A.GROUPCODE='HCDLW' THEN 'DELAWARE' WHEN A.GROUPCODE='HCMTG' THEN 'MONTGOMERY' END, A.GROUPCODE, RATEGROUPDESC, PROVIDERMISID, A.SERVICECATEGORYCODE, SERVICECATEGORYDESC, SERVICESTARTMONTH, PAIDDATE, TOTALPAIDAMOUNT, UNIQUEMEMBERCOUNT, UNITS, PAIDAMOUNT FROM TBL1 A, TBL2 B, TBL3 C WHERE PAIDDATE between 20180701 and 20180731 AND A.RATEGROUPCODE = B.RATEGROUPCODE AND A.SERVICECATEGORYCODE = SUBSTR(C.SERVICECATEGORYCODE,1,2) ORDER BY substr(PAIDDATE,1,6),A.GROUPCODE, PROVIDERMISID,RATEGROUPDESC, PAIDDATE;