是否有一个LIKE子句用于在SQL中查询XML

时间:2010-09-16 12:45:28

标签: sql xml

我正在使用SQL Server 2005,我想知道是否有办法在我的xml搜索中执行LIKE子句。

以下是一个示例查询:

            SELECT  Id, CaseNumber, XmlTest
            FROM UploadReport 
            WHERE 
            CASE 
                  WHEN @lastName != '' AND XmlTest.exist('(/CodeFiveReport/Parties/Party/Name/LastName[text()=sql:variable("@lastName")])') = 1 THEN 1
                  WHEN @firstName != '' AND XmlTest.exist('(/CodeFiveReport/Parties/Party/Name/FirstName[text()=sql:variable("@firstName")])') = 1 THEN 1
                  WHEN @middleName != '' AND XmlTest.exist('(/CodeFiveReport/Parties/Party/Name/MiddleName[text()=sql:variable("@middleName")])') = 1 THEN 1
                  WHEN @ssn != '' AND XmlTest.exist('(/CodeFiveReport/Parties/Party/SocialSecurityNumber[text()=sql:variable("@ssn")])') = 1 THEN 1             
                  ELSE 0
            END = 1

我想基本上做WHERE LastName like @lastName + '%'

编辑:

工作查询:

    SELECT  Id, CaseNumber, XmlTest
            FROM UploadReport 
            WHERE 
                 XmlTest.exist('(/CodeFiveReport/Parties/Party/Name/LastName[contains(text()[1], "Sm")])') = 1 

1 个答案:

答案 0 :(得分:3)

您是否尝试过contains()

[contains(sql:variable("@lastName"))]