Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

How can I concatenate all of
SQL
CACSE(...)
result rows into into one?
Additionaly - is there a way to group multiple statements without "MAX" added into single entry?

Please check lines below, I might have been mistaken with part of it:

select				
max(case when source_column_a in (value_1) then value else null) as "value_a",				
(case when source_column_a in (value_2) then value else null) as "value_b",				
(case when source_column_a in (value_3) then value else null) as "value_c",				
max(case when source_column_a in (value_4) then value else null) as "value_d"				
from table				
group by ID, (case when source_column_a in (value_2) then value else null), (case when source_column_a in (value_3) then value else null);				
				
				
example result:				
	value_a	value_b	value_c	value_d
	Amax	(null)	(null)	Dmax
	(null)	B1	    (null)	(null)
	(null)	B2	    (null)	(null)
	(null)	B3	    (null)	(null)
	(null)	Bmax	(null)	(null)
	(null)	(null)	C1	    (null)
	(null)	(null)	C2	    (null)
	(null)	(null)	C3	    (null)
	(null)	(null)	Cmax	(null)
				
				
Results to achieve:				
	value_a	value_b	value_c	value_d
	Amax	Bmax	CMax	Dmax
	(null)	B3	    C3	    (null)
	(null)	B2	    C2	    (null)
	(null)	B1	    C1	    (null)
				
	value_a	value_b	value_c	value_d
	Amax	Bmax, B3, B2, B1	Cmax, C3, C2, C1	Dmax

Regards,

What I have tried:

In situation related to additional one - query might have been modified more than once to include at least one of the cases in group by.
Posted
Updated 28-Nov-17 11:28am
v2
Comments
RossMW 26-Nov-17 19:38pm    
It might help if you gave an example of the result you after.

If you are trying to have a case result in a field then use something like

Select CASE    WHEN Fieldname = 'A' THEN 1;    WHEN Fieldname = 'B' THEN 2;    WHEN fieldname = 'C' THEN 3;    End case;as Fieldname
Member 13323381 27-Nov-17 17:00pm    
Please check lines below, I might have been mistaken with part of it:

select				
max(case when source_column_a in (value_1) then value else null) as "value_a",				
(case when source_column_a in (value_2) then value else null) as "value_b",				
(case when source_column_a in (value_3) then value else null) as "value_c",				
max(case when source_column_a in (value_4) then value else null) as "value_d"				
from table				
group by ID, (case when source_column_a in (value_2) then value else null), (case when source_column_a in (value_3) then value else null);	
				
example result:				
	value_a	value_b	value_c	value_d
	Amax	(null)	(null)	Dmax
	(null)	B1	    (null)	(null)
	(null)	B2	    (null)	(null)
	(null)	B3	    (null)	(null)
	(null)	Bmax	(null)	(null)
	(null)	(null)	C1	    (null)
	(null)	(null)	C2	    (null)
	(null)	(null)	C3	    (null)
	(null)	(null)	Cmax	(null)
				
				
Results to achieve:				
	value_a	value_b	value_c	value_d
	Amax	Bmax	CMax	Dmax
	(null)	B1	    C1	    (null)
	(null)	B2	    C2	    (null)
	(null)	B3	    C3	    (null)
				
	value_a	value_b	value_c	value_d
	Amax	Bmax, B1, B2, B3	Cmax, C1, C2, C3	Dmax
Patrice T 27-Nov-17 17:35pm    
Use Improve question to update your question.
So that everyone can pay attention to this information.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900