pandemkodi Posted November 3, 2017 Report Posted November 3, 2017 idi naa source table DB2 pk code value 1 code1 10 2 code2 100 3 code 3 1000 target code1 code2 code3 10 100 1000 naku ila vastondi case stmt tho code1 code2 code 3 10 null null null 100 null null null 1000 NUlls raakudadhu and all in single row lo ravali please help Quote
Bhai Posted November 3, 2017 Report Posted November 3, 2017 17 minutes ago, pandemkodi said: idi naa source table DB2 pk code value 1 code1 10 2 code2 100 3 code 3 1000 target code1 code2 code3 10 100 1000 naku ila vastondi case stmt tho code1 code2 code 3 10 null null null 100 null null null 1000 NUlls raakudadhu and all in single row lo ravali please help nee code padeyyi ikkada. andhulo bokkalu ento chebutaru Quote
pandemkodi Posted November 3, 2017 Author Report Posted November 3, 2017 this is what i am using select (CASE WHEN CODE ='CODE1' THEN VALUE END) AS CODE1, (CASE WHEN CODE ='CODE2' THEN VALUE END) AS CODE2, (CASE WHEN CODE ='CODE3' THEN VALUE END) AS CODE3 FROM TABLE1 Quote
ponugupati Posted November 3, 2017 Report Posted November 3, 2017 https://www.techonthenet.com/oracle/pivot.php use pivot Quote
pandemkodi Posted November 3, 2017 Author Report Posted November 3, 2017 3 minutes ago, ponugupati said: https://www.techonthenet.com/oracle/pivot.php use pivot db2 lo pivot ledu bayya ..Thanks Quote
Bhai Posted November 3, 2017 Report Posted November 3, 2017 7 minutes ago, ponugupati said: https://www.techonthenet.com/oracle/pivot.php use pivot not all dbs support pivot Quote
pandemkodi Posted November 3, 2017 Author Report Posted November 3, 2017 40 minutes ago, reality said: Use Coalesce can u explain more bayya..i cant even aggregate as well Quote
prabhu_pramod Posted November 3, 2017 Report Posted November 3, 2017 OPTION#1: You can add MAX or MIN to your each of CASE statement option#2: create a function which will take input as ID and return value Quote
pushparajukatre Posted November 3, 2017 Report Posted November 3, 2017 anni case statements mundu max petti try cheyi vasthundi Quote
reality Posted November 3, 2017 Report Posted November 3, 2017 42 minutes ago, pandemkodi said: can u explain more bayya..i cant even aggregate as well You just have to put colums (or) expressions for those columns (like case stmt) inside coalesce function... like coalesce (expression1, expression2, column3, etc) Quote
reality Posted November 3, 2017 Report Posted November 3, 2017 Select Coalesce (CASE WHEN CODE ='CODE1' THEN VALUE END) AS CODE1, Coalesce (CASE WHEN CODE ='CODE2' THEN VALUE END )AS CODE2, Coalesce (CASE WHEN CODE ='CODE3' THEN VALUE END) AS CODE3) FROM TABLE1 Corrected...try Quote
JollyBoy Posted November 3, 2017 Report Posted November 3, 2017 @pandemkodi use this DECLARE @col NVARCHAR(MAX),@sql NVARCHAR(MAX); SELECT @col= COALESCE(@col, '') + ',''' + value +''' as ['+ code+']' FROM tablename SELECT @sql = 'select ' +stuff(@col,1,1,''); exec(@sql) Quote
4Vikram Posted November 3, 2017 Report Posted November 3, 2017 54 minutes ago, JollyBoy said: @pandemkodi use this DECLARE @col NVARCHAR(MAX),@sql NVARCHAR(MAX); SELECT @col= COALESCE(@col, '') + ',''' + value +''' as ['+ code+']' FROM tablename SELECT @sql = 'select ' +stuff(@col,1,1,''); exec(@sql) Quote
pandemkodi Posted November 3, 2017 Author Report Posted November 3, 2017 1 hour ago, pushparajukatre said: anni case statements mundu max petti try cheyi vasthundi max or min chestey i will loose some values ..will not work for my case Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.