pandemkodi Posted November 3, 2017 Author Report Posted November 3, 2017 1 hour 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) Wow Thanks bayya ..its working but all the codes coming as columns ..for example if code1 is present twice then code1 column coming 2 times but i need like below ..value should come as row if same code value is present pk code value 1 code1 10 2 code2 100 3 code 3 1000 4 code1 20 expected : Code1 code 2 code 3 10 100 1000 20 NULL NULL coming as code1 code2 code3 code1 10 100 1000 20 Quote
JollyBoy Posted November 3, 2017 Report Posted November 3, 2017 15 minutes ago, pandemkodi said: Wow Thanks bayya ..its working but all the codes coming as columns ..for example if code1 is present twice then code1 column coming 2 times but i need like below ..value should come as row if same code value is present pk code value 1 code1 10 2 code2 100 3 code 3 1000 4 code1 20 expected : Code1 code 2 code 3 10 100 1000 20 NULL NULL coming as code1 code2 code3 code1 10 100 1000 20 I am not DB2 guy but use these https://www.ibm.com/developerworks/community/blogs/SQLTips4DB2LUW/entry/pivoting_tables56?lang=en https://stackoverflow.com/questions/13579143/how-can-i-pivot-a-table-in-db2 Quote
ringaringa Posted November 3, 2017 Report Posted November 3, 2017 Babu Google chesuko illanti lacha untayyi solutions..... 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.