Wednesday, 9 September 2015

How to convert rows in to column

--How to get ids in one line usign , Delimeted 

DECLARE @planids TABLE (Id INT)
INSERT INTO @planids VALUES (123),(234),(343),(543),(45345),(543),(4534)
SELECT * FROM @planids

DECLARE @plans varchar(max)
SET @plans = ''

SELECT  @plans = @plans+ cast(Id AS varchar(12)) +',  '
FROM @planids 
--where ParentPlanId in (373289)

SELECT @plans AS PlanList



No comments:

Post a Comment