| a1 | a2 | a3 |
| 11 | null | null |
| null | 12 | null |
| null | null | 13 |
in this table i want output as follows
| D1 |
| 11 |
| 12 |
| 13 |
Give This Output
| a1 | a2 | a3 |
| 11 | null | null |
| null | 12 | null |
| null | null | 13 |
| D1 |
| 11 |
| 12 |
| 13 |
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Jun 17, 2015, 1:32 AM EDT
Khan Abrar AhmedRank #778 · 3K reputationPosted Jun 15, 2015, 11:49 PM EDT
Sabyasachi MishraRank #889 · 2.4K reputationPosted Jun 16, 2015, 12:24 AM EDT
Avinash Vajpayee71 reputationPosted Jun 16, 2015, 9:29 PM EDT
Avinash Vajpayee71 reputationPosted Jun 16, 2015, 9:39 PM EDT
Sabyasachi MishraRank #889 · 2.4K reputationPosted Jun 17, 2015, 1:01 AM EDT
Sabyasachi MishraRank #889 · 2.4K reputationPosted Jun 17, 2015, 1:04 AM EDT
(
SELECT a1 as D1 FROM dbo.yourtable where a1 IS NOT NULL
UNION ALL
SELECT a2 as D1 FROM dbo.yourtable where a2 IS NOT NULL
UNION ALL
SELECT a3 as D1 FROM dbo.yourtable where a3 IS NOT NULL
) A Where D1 IS NOT NULL
Group by D1
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Jun 22, 2015, 4:33 AM EDT