我正在尝试比较SQL查询中的2个字符串列,但无法这样做。
以下是我要执行的查询:
With tempTable as
(
Select
Id, DTree.Name, DefID, ValStr, DTree.DComment
from
LLAttrData la, DTree
where
DefId = 726297 and
DTree.DataId = la.ID and
ValStr IS NOT NULL
and AttrId in (3)
)
SELECT
Id, Name, DefID, DComment,
STUFF((SELECT ', ' + CAST(ValStr AS VARCHAR(20)) [text()]
FROM tempTable
WHERE ID = t.ID
FOR XML PATH(''), TYPE).value('.','NVARCHAR(MAX)'), 1, 2, ' ') List_Output
FROM
tempTable t
WHERE
DComment NOT LIKE STUFF((SELECT ', ' + CAST(ValStr AS VARCHAR(20))
[text()]
FROM tempTable
WHERE ID = t.ID
FOR XML PATH(''), TYPE).value('.','NVARCHAR(MAX)'), 1, 2, ' ')
GROUP BY
Id, Name, DefID, DComment
下面是我得到的结果的屏幕截图:
如您所见,DComment
和List_Output
列的内容完全相似。根据我的查询,应该没有显示任何结果
(因为我使用NOT LIKE运算符进行比较)
有人可以帮我这个忙吗?谢谢!