SQLTeam.com | Weblogs | Forums

How to separate value exist on temp table dynamically separated by comma?

problem

How to separate value exist on temp table dynamically separated by comma ?

i work on sql server 2012 i need to separate field TeamName by comma

teamname ,teamname+'Date'

i need to loop to teamname filed in tmp table #Teams then separate by comma and every field will be next field + 'Date'

really #temp table #teams every time changed so i dont have static data so i need any way dynamically sepatae field

and second will be field+date

CREATE TABLE #Teams
(
TeamId int,
TeamName  nvarchar(200)
)
insert into #Teams(TeamId,TeamName) values
 (1,'Package'),
 (2,'Parametric'),
 (3,'Scribing'),
 (4,'Lifecycle')
 select * from #Teams

i need result as
Package,PackageDate,Parametric,ParametricDate,Scribing,ScribingDate,Lifecycle,LifecycleDate

DECLARE @all_teams nvarchar(max)=N'';
SELECT @all_teams += TeamName + N',' + TeamName + N'Date,'
FROM #teams
SELECT SUBSTRING(@all_teams,1,LEN(@all_teams)-1) -- removes last comma