Use a LIKE statement on SQL Server XML Datatype

前端 未结 4 1291
面向向阳花
面向向阳花 2020-12-30 18:21

If you have a varchar field you can easily do SELECT * FROM TABLE WHERE ColumnA LIKE \'%Test%\' to see if that column contains a certain string.

How do

4条回答
  •  春和景丽
    2020-12-30 19:01

    Another option is to search the XML as a string by converting it to a string and then using LIKE. However as a computed column can't be part of a WHERE clause you need to wrap it in another SELECT like this:

    SELECT * FROM
        (SELECT *, CONVERT(varchar(MAX), [COLUMNA]) as [XMLDataString] FROM TABLE) x
    WHERE [XMLDataString] like '%Test%'
    

提交回复
热议问题