I have 2 tables:
Table 1
id question customerId
1 bla1 1
2 bla2 2
Table 2
id customerId Key Value
1 1 firstname John
2 1 lastname Doe
3 2 firstname Billy
4 2 lastname Jones
I need to get my gridview to show:
Row 1: John Doe Bla1
Row 2: Billy Jones Bla2
Currently it shows: (but I dont want it like this):
Row 1: John Bla1
Row 2: Doe Bla1
Row 3: Billy Bla2
Row 4: Jones Bla2
I think I have tried everything and could use your help! Thanks.
SELECT [firstname],[lastname], question
FROM
(
SELECT a.question, b.[key], b.[value]
FROM Table1 a
INNER JOIN Table2 b
ON a.customerID = b.CustomerID
) org
PIVOT
(
MAX([value])
FOR [KEY] IN ([firstname],[lastname])
) pvt
OUTPUT
╔═══════════╦══════════╦══════════╗
║ FIRSTNAME ║ LASTNAME ║ QUESTION ║
╠═══════════╬══════════╬══════════╣
║ John ║ Doe ║ bla1 ║
║ Billy ║ Jones ║ bla2 ║
╚═══════════╩══════════╩══════════╝
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With