Я надеюсь, что следующий запрос SQL также может помочь вам
create table myTable (
ReferenceId int,
Contract int,
Tender int,
Waiver int,
Quotation int
)
insert into myTable select 1212,1,0,1,0
insert into myTable select 1213,1,1,0,0
insert into myTable select 1214,0,1,0,0
insert into myTable select 1215,1,0,1,0
insert into myTable select 1216,0,0,0,1
insert into myTable select 1217,0,0,1,0
insert into myTable select 1218,0,0,0,0
;with cte as (
select
*,
ISNULL(NULLIF(
CONCAT_WS(',',
case when Contract = 1 then 'Contract' end,
case when Tender = 1 then 'Tender' end,
case when Waiver = 1 then 'Waiver' end,
case when Quotation = 1 then 'Quotation' end
)
,''),'None')
as Category
from myTable
)
select
ReferenceId, Contract, Tender, Waiver, Quotation, c.val as Category
from cte
cross apply split(Category,',') as c
Здесь вам нужна пользовательская SQL функция SPLIT , где можно найти исходные коды
Вывод следующий: