嘿,我正在使用以下查询来显示以逗号分隔的问题列表。
SELECT tt.VrNo, STUFF((select ','+ Er1.ErrorDesc
from ( select * from CallRegErrors )as Main
left join ErrorMaster ER1 on Main.ErrorCode=ER1.ErrorCode
WHERE (main.VrNo = tt.VrNo)
FOR XML PATH('')) ,1,1,'') AS Problemlist
查询给出的输出如 a、b、c、d 等
但我的实际要求是我想在新行中显示每个错误描述,例如
a
b
c
d
等
我尝试了以下查询:
SELECT tt.VrNo, STUFF((select char(13)+char(10)+ Er1.ErrorDesc
from ( select * from CallRegErrors )as Main
left join ErrorMaster ER1 on Main.ErrorCode=ER1.ErrorCode
WHERE (main.VrNo = tt.VrNo)
FOR XML PATH('')) ,1,1,'') AS Problemlist
我也用过
SELECT tt.VrNo,Replace(STUFF((select ','+ Er1.ErrorDesc as [text()] from (select * from CallRegErrors)as Main left join ErrorMaster ER1 on Main.ErrorCode=ER1.ErrorCode WHERE (main.VrNo = tt.VrNo) FOR XML PATH('')),1,1,''),',',char(13)+char(10)) AS Problemlist from (select main.VrNo, Er1.ErrorDesc from ( select * from CallRegErrors ) as Main left join ErrorMaster ER1 on Main.ErrorCode=ER1.ErrorCode ) as tt group by tt.VrNo 但现在使用上述查询后得到由空格而不是逗号分隔的问题列表
但它没有给出我想要的输出。
请帮忙..
提前致谢