I have a table A with columns as below:
Addr_id Street_Add Addr_type_cd Acct_nbr CITY
1 12 ST PROP A MN
1 12 ST MAIL A1 MN
1 12 ST PROP B MN
1 12 ST PROP A MN
1 12 ST PROP A MN
2 13 ST PROP A2 MI
2 13 ST MAIL A3 MI
3 14 ST PROP AB MO
4 15 ST MAIL AD IL
Output is as below;
OUTPUT - ADDR_ID OUTPUT - ADDR_TYPE_ CD
1 PROP
1 MAIL
1 RPT
2 PROP
2 MAIL
2 RPT
3 PROP
3 RPT
4 MAIL
4 RPT
The natural key is Street_addr and CITY. I am trying to write a Case expression populating another column ADDR_TYPE_CD in Table B based on below rules
- WHERE STREET_ADD=STREET_ADD and CITY=CITY
- IF ADDR_TYPE_cd= PROP and MAIL,
- THEN ADDR_TYPE_CD in TABLE B = PROP, MAIL, RPT
- IF ADDR_TYPE_cd= PROP
- THEN ADDR_TYPE_CD in TABLE B = PROP, RPT
- IF ADDR_TYPE_cd= MAIL
- THEN ADDR_TYPE_CD in TABLE B = MAIL, RPT
I have tried writing through CASE statement as :
SELECT
CASE addr_type_cd
WHEN addr_type_cd='PROP' AND addr_type_cd='MAIL'
THEN addr_type_cd='RPT' AND addr_type_cd='PROP' AND addr_type_cd='MAIL'
END
FROM Table A
WHERE street_addr = street_addr
AND city = city
I get missing keyword error, plus am not sure if the logic would work. Any inputs ideas will be very helpful. Hope the question is clear.
Thanks,
Pallavi
street_addr
NOT equalstreet_addr
or `city
NOT equalcity
when they're the same column in the same row? IOW, your logic as written will always return every single row, because the columns will always be equal.