You can also use CASE
statement like so:
create table test (
id int,
building int,
heavy int,
municipal int,
industry int
);
insert into test values (101, 1, 1, 0, 1);
with data as (
select id,
case when building = 1 then 'Building,' else '' end +
case when heavy = 1 then 'Heavy,' else '' end +
case when municipal = 1 then 'Municipal,' else '' end +
case when industry = 1 then 'Industry,' else '' end as fld
from test
)
select id, left(fld, len(fld)-1) as fld from data;
Example: http://rextester.com/CKGES46149
Result:
id fld
101 Building,Heavy,Industry
If a space after comma is needed, add a slight modification like so:
with data as (
select id,
rtrim(
case when building = 1 then 'Building, ' else '' end +
case when heavy = 1 then 'Heavy, ' else '' end +
case when municipal = 1 then 'Municipal, ' else '' end +
case when industry = 1 then 'Industry, ' else '' end
) as fld
from test
)
select id, left(fld, len(fld)-1) as fld from data;
Result:
id fld
101 Building, Heavy, Industry
Example: http://rextester.com/OJNEQ98420