Table 1:
ID AUDIT_KEY Col_Name
1 100 FULL NAME
2 101 FNAME
3 102 LNAME
4 103 ADDR1
Table 2:
ID_key AUDITKEY Col_Value
1 100 john abraham
2 101 johny
3 102 Abraham
4 103 6900 Forester Rd
1 104 Praveen Gupta
2 105 Praveen
3 106 Gupta
4 107 3200 Walter RD
Looking for QUERY TO FORM THE RESULT AS BELOW
ID NAME FNAME LNAME ADDR1
1 JOHN ABRAHAM JOHNY ABRAHAM 6900 Forester Rd
2 PRAVEEN GUPTA PRAVEEN GUPTA 3200 WALTER RD
Written pivot query on table1 when i join table2 based on the ID & ID_KEY is not working.. any idea folks..
SELECT ID, NAME,FNAME,LNAME,ADDR1
FROM TABLE1
INNER JOIN TABLE2 ON TABLE1.ID = TABLE2.ID
PIVOT (MAX(TABLE1.COL_NAME)
FOR TABLE2.COL_VALUE IN ('ID','NAME','FNAME','LNAME','ADDR1')) AS TMP
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…