query in CASE expression in select [message #632800] |
Thu, 05 February 2015 17:20  |
 |
pallaviprakash
Messages: 2 Registered: February 2015
|
Junior Member |
|
|
Hi,
I have a table A with columns and Ouput is Table B

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
|
|
|
|
|
|
|
|
| Re: query in CASE expression in select [message #632822 is a reply to message #632800] |
Fri, 06 February 2015 01:49  |
John Watson
Messages: 9004 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
Can you describe the whole question (I assume this is a colege homework question?) again? And of course include the CREATE TABLE statement and the seven INSERT statements.
There is a lot I can't understand at the moment. For example, you say "The natural key is Street_addr and CITY" but they do not give you a unique identifier. Furthermore, your table has seven rows but your output has twelve rows, which seems odd.
|
|
|
|