SELECT sc.CID,sc.CodeName as OverviewText,scRAG.CodeName as RAGStatusText
FROM StatusCode sc
LEFT OUTER JOIN ProjectOverview po ON sc.CID = po.ProjectOverviewCID AND po.ProjectId = 180
LEFT OUTER JOIN StatusCode scRAG ON po.RAGStatusCID = scRAG.CID
WHERE sc.SCID = 18
上面的代码结果是这样的:
CID OverviewText RAGStatusText
153 Cost Green
154 Requirements Yellow
155 Schedule NULL
156 Technical NULL
157 Testing NULL
我希望它返回一个包含10个字段的记录:
成本,绿色,要求,黄色, Schedule,NULL, 技术,NULL, 测试,NULL
我可以在cid上转动吗?
答案 0 :(得分:0)
您可以使用一列,而不是使用单独的列吗?喜欢这个?
create table #t1([CID] int
,[OverviewText] varchar(12)
,[RAGStatusText] varchar(6))
insert #t1 values (153,'Cost','Green')
insert #t1 values (154,'Requirements','Yellow')
insert #t1 values (155,'Schedule',NULL)
insert #t1 values (156,'Technical',NULL)
insert #t1 values (157,'Testing',NULL)
select StringToSpit = stuff((select
[text()]=','+[OverviewText]+','+isnull([RAGStatusText],'NULL')
from #t1
for xml path('')),1,1,'')