这是我的视图文件。我需要将joint_list过滤到joint_list NOT IN(' 0')。任何人都可以帮我如何过滤掉它。这是代码的输出。 view files
SELECT CUSTID,SPAID,STUFF((SELECT ', ' + CAST(RTrim(user1) AS VARCHAR(Max)) [text()]
FROM xtcwt_JointAcc(nolock)
WHERE CUSTID = t.custid and SPAID = t.SPAID and Status='A'
FOR XML PATH(''), TYPE)
.value('.','NVARCHAR(MAX)'),1,2,' ') joint_list
FROM xtcwt_JointAcc t with(nolock)
GROUP BY CUSTID,SPAID
谢谢!!
答案 0 :(得分:1)
将您的查询放入sub-select/CTE
并过滤joint_list
外部
SELECT *
FROM (SELECT CUSTID,
SPAID,
Stuff((SELECT ', ' + Cast(Rtrim(user1) AS VARCHAR(Max)) [text()]
FROM xtcwt_JointAcc(nolock)
WHERE CUSTID = t.custid
AND SPAID = t.SPAID
AND Status = 'A'
FOR XML PATH(''), TYPE) .value('.', 'NVARCHAR(MAX)'), 1, 2, ' ') joint_list
FROM xtcwt_JointAcc t WITH(nolock)
GROUP BY CUSTID,
SPAID) a
WHERE joint_list <> '0'