尝试通过比较小写/大写

时间:2016-11-10 20:22:50

标签: sql sql-server

希望这是有道理的。只是尝试基于相同的文件路径字符串连接2个表:

SELECT DISTINCT (vdir_physicalPath)
FROM dbo.ASPR_IisVdir --gets all distinct paths for the virtual directories

--now I need to list only the records where the 'path' matches ANY of the rows from the results above;
SELECT *
FROM dbo.ASPR_FolderAcl
WHERE UPPER(fullname) = ANY OF the rows above

--notice that the strings are lowercase/uppercase plus vdir_physicalPath has an extra '/'
--I tried to inner join but it didnt list me anything; something like:
SELECT *
FROM dbo.ASPR_FolderAcl acl
INNER JOIN dbo.ASPR_IisVdir vdir
    ON UPPER(acl.fullname) + '/' = UPPER(vdir.vdir_physicalPath) collate SQL_Latin1_General_CP1_CS_AS
        --
        --when comparing should I use something like CHARINDEX(UPPER(fullname), vdir_physicalPath) > 0 

enter image description here

enter image description here

感谢 最大

2 个答案:

答案 0 :(得分:3)

为什么不简单地使用不区分大小写的排序规则,例如SQL_Latin1_General_CP1_CI_AS而不是SQL_Latin1_General_CP1_CS_AS? AFAIK,这也可以通过调用UPPER来节省你所支付的任何轻微性能损失,并允许仍然使用表上的任何索引。

有关详细信息,请阅读Collation and Unicode Support

如果您切换排序规则并且仍有问题,那么根据目前提供的信息,您的逻辑可能有问题,或者您的数据中可能有gremlins(例如零宽度空间)。

答案 1 :(得分:0)

使用SQL_Latin1_General_CP1_CS_AS并在示例中使用斜杠/代替反斜杠\