Hi Team,
I need to write a SQL to cater the requirements. Below is my requirements:
pagename fieldname fieldvalue account_number consumerID AFAccountUpdate ArrangementsBroken dfsdff 1234 1234 AFAccountUpdate ArrangementsBroken1 dfsdff 1234 1234 AFAccountUpdate ArrangementsBroken2 dfsdff 1234 1234 AFAccountUpdate ArrangementsBroken2 dfsdff 12345 12345 AFAccountUpdate ArrangementsBroken1 addf 12345 12345 Create table test_pivot_dynamic ( pagename varchar(200), fieldname Varchar(200), fieldvalue varchar(500), N9_Router_Account_Number bigint, TC_Debt_Item_Reference bigint ) --Input insert into test_pivot_dynamic Values('AFAccountUpdate','ArrangementsBroken','addf',1234,1234) insert into test_pivot_dynamic Values('AFAccountUpdate','ArrangementsBroken1','dfsdff',1234,1234) insert into test_pivot_dynamic Values('AFAccountUpdate','ArrangementsBroken2','fder',1234,1234) insert into test_pivot_dynamic Values('AFAccountUpdate','ArrangementsBroken2','dfdfs',12345,12345) insert into test_pivot_dynamic Values('AFAccountUpdate','ArrangementsBroken1','dfdwe',12345,12345) insert into test_pivot_dynamic Values('AFAccountUpdate1','Arrangements','addf',1234,1234) insert into test_pivot_dynamic Values('AFAccountUpdate1','Test1','dfsdff',1234,1234) --Expected output: Select 1234,1234,'AFAccountUpdate','ArrangementsBroken','addf','ArrangementsBroken1','dfsdff','ArrangementsBroken2','fder','ArrangementsBroken2','fder' Select 12345,12345,'AFAccountUpdate','ArrangementsBroken','addf','ArrangementsBroken1','dfdwe','ArrangementsBroken2','dfdfs' Select 1234,1234,'AFAccountUpdate1','Arrangements','addf','Test1','dfsdff'
so basically we have to pivot and dynamic sql and insert the expected output to a common table which will have all the required fields
Thanks,Ram.
Please don't forget to Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful. It will helpful to other users.