Home » SQL & PL/SQL » SQL & PL/SQL » shortest way to concatenate multiple messages based on column multiple values. (Oracle 11g)
shortest way to concatenate multiple messages based on column multiple values. [message #603047] Wed, 11 December 2013 03:28 Go to next message
ajaykumarkona
Messages: 399
Registered: August 2010
Senior Member
Hi Experts,

I have written the below query to display message based on one "N" value.

SELECT CASE 
                          WHEN CONSUMER_VALID = 'N' THEN 'CONSUMER'||'  '||CONSUMER||'  '||'IS NOT EXISTED'
                          WHEN CID_VALID ='N' THEN 'C_ID'||'  '||C_ID||'  '||'IS NOT EXISTED' 
                          WHEN LOC_VALID = 'N' THEN 'LOCATION'||'  '||LOCATION||'  '||'IS NOT EXISTED'
                          WHEN PERIOD_VALID = 'N' THEN 'PERIOD'||'  '||PERIOD||'  '||'IS NOT EXISTED'
                          ELSE 'No MESSAGE' 
                          END AS MESSAGE 
                          FROM CONSUMER_DETAILS;



If multiple "N" values are there for one record it should concatenate multiple messages and show.

For Example for the below record
the message should be C_ID  180  IS NOT EXISTED AND LOCATION  ABC  IS NOT EXISTED

C0814818	35	180	ABC			Y		Y	    N	        N

If I write as above I have to write multiple CASE statements for all combinations.
It will bocome lengthy code.Is there any shortest way to write the query.

The data as below in the table.

CONSUMER	PERIOD	C_ID	LOCATION       CONSUMER_VALID	PERIOD_VALID	CID_VALID   LOC_VALID	
C0814826	105	160	BANG	                Y		N	    Y	        Y	
S0814827	103	666	SDF			N		N	    N	        N	
C0814818	30	190	HYD			Y		Y	    N	        Y	
C0814818	35	180	ABC			Y		Y	    N	        N	
C0814830	0	160	SRT			Y		N	    Y	        N	
C0814831	0	160	BANG			Y		N	    Y	        Y	
C0814828	0	160	BANG			Y		N	    Y	        Y	
C0814829	300	160	BANG			Y		N           Y	        Y	
C0814832	150	200	BANG			Y		N	    N	        Y	


Please help me.

Thanks.
Re: shortest way to concatenate multiple messages based on column multiple values. [message #603048 is a reply to message #603047] Wed, 11 December 2013 03:31 Go to previous messageGo to next message
martijn
Messages: 286
Registered: December 2006
Location: Netherlands
Senior Member
see if decode() can help you.
Re: shortest way to concatenate multiple messages based on column multiple values. [message #603050 is a reply to message #603048] Wed, 11 December 2013 03:40 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
martijn wrote on Wed, 11 December 2013 15:01
see if decode() can help you.


Even with decode OP would have to write multiple decode statements for each expression.
Re: shortest way to concatenate multiple messages based on column multiple values. [message #603052 is a reply to message #603050] Wed, 11 December 2013 03:48 Go to previous messageGo to next message
martijn
Messages: 286
Registered: December 2006
Location: Netherlands
Senior Member
Lalit Kumar B wrote on Wed, 11 December 2013 10:40
martijn wrote on Wed, 11 December 2013 15:01
see if decode() can help you.


Even with decode OP would have to write multiple decode statements for each expression.

Yup that's right.

But as far as I understood the question, I think that, one way or another, the different columns need to be checked for 'Y' or 'N'.
Decode always is a helpfull compadre to me, dor this kind of problems.

(Or...I didn't read the question good enough, and now I am way off)
Re: shortest way to concatenate multiple messages based on column multiple values. [message #603055 is a reply to message #603052] Wed, 11 December 2013 03:56 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
martijn wrote on Wed, 11 December 2013 15:18
the different columns need to be checked for 'Y' or 'N'.


OP has mentioned that he wants to only check for value 'N'. And the same value needs to be checked for different expressions.

@ajaykumarkona, after close to 400 posts, you should provide the DDLs and insert statements alongwith your question. And post the required output.
Re: shortest way to concatenate multiple messages based on column multiple values. [message #603059 is a reply to message #603047] Wed, 11 December 2013 04:02 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Do not use one single CASE/DECODE but one per condition to test and concatenate them.

Re: shortest way to concatenate multiple messages based on column multiple values. [message #603080 is a reply to message #603059] Wed, 11 December 2013 05:44 Go to previous messageGo to next message
ajaykumarkona
Messages: 399
Registered: August 2010
Senior Member
Hi All,

Thanks for your suggestions.
I have done .

Thanks.
Re: shortest way to concatenate multiple messages based on column multiple values. [message #603082 is a reply to message #603080] Wed, 11 December 2013 05:45 Go to previous message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

How? Show us.

Previous Topic: ora-20000: unable to analyze table
Next Topic: external table
Goto Forum:
  


Current Time: Thu Apr 25 07:46:05 CDT 2024