Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 combine rows into column

Author  Topic 

byka
Starting Member

18 Posts

Posted - 2014-07-31 : 14:29:57
how can i combine rows into 1 column per each ExclusionID
SELECT
sept.ExclusionID,
pt.PolicyTypeDesc
FROM dbo.StateExclusionPlanTypes sept JOIN dbo.PolicyTypes pt
ON sept.PolicyTypeID=pt.PolicyTypeID


byka

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-08-01 : 11:05:46
something like this?


declare @StateExclusionPlanTypes table(PolicyTypeId int, ExclusionID int)
insert into @StateExclusionPlanTypes(PolicyTypeId, ExclusionID) values
(1, 42), (1, 43), (2,43)
declare @PolicyTypes table(PolicyTypeID int, PolicyTypeDesc varchar(50))
insert into @PolicyTypes(PolicyTypeID, PolicyTypeDesc) values
(1, 'one'), (2, 'two')


select distinct(sept.ExclusionID), (
select pt.PolicyTypeDesc+ ': '
from @PolicyTypes pt
join @StateExclusionPlanTypes sept1
on sept1.PolicyTypeID=pt.PolicyTypeID
and sept1.ExclusionID = sept.ExclusionID
for xml path(''))
from @StateExclusionPlanTypes sept
Go to Top of Page
   

- Advertisement -