Hi @MrFlinstone
According to your description, it seems that you want to perform a column-to-row operation.
Here I recommend two methods:
One is to use Cross Apply:
SELECT DISTINCT Name,Groups
FROM your_dataset CROSS APPLY(VALUES(Group1,'Group1'),
(Group2,'Group2'))U(Groups,Group1or2)
WHERE Groups IS NOT NULL AND Groups<>''
The other is to use the UNPIVOT keyword,check this:
SELECT DISTINCT Name,Groups
FROM your_dataset UNPIVOT(Groups FOR Group1or2 IN ([Group1],[Group2]))U
WHERE Groups IS NOT NULL AND Groups <>''
Best regards,
LiHong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.