Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
sicdude
Contributor III
Contributor III

SQL Select case statement to alias field data

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;

1 Solution

Accepted Solutions
felipedl
Partner - Specialist III
Partner - Specialist III

Depends on the SQL you're using, but should be actually something like

case COUNTYCODE

when 'HCBUC' THEN 'BUCKS'

when 'HCDLW' THEN 'DELAWARE'

when 'HCMTG' THEN 'MONTGOMERY'

end 

Felipe.

 

View solution in original post

2 Replies
felipedl
Partner - Specialist III
Partner - Specialist III

Depends on the SQL you're using, but should be actually something like

case COUNTYCODE

when 'HCBUC' THEN 'BUCKS'

when 'HCDLW' THEN 'DELAWARE'

when 'HCMTG' THEN 'MONTGOMERY'

end 

Felipe.

 

sicdude
Contributor III
Contributor III
Author

yes that was it...silly mistake.  thank you!