Tech Talk A software developer on all things tech, and then some

31Jan/130

Argument data type xml is invalid for argument 1 of like function

If you haven't realized it by now, you cannot do a LIKE without any magic on a XML column. If you do, you will get the following error :

Argument data type xml is invalid for argument 1 of like function

If you need to do a LIKE on a column with XML, there are a few ways to go about it. I however for the most part just need to do this through SQL Server Management Studio, so I use the quick solution of converting it to a varchar field, and problem solved. This would look like the following :

SELECT * FROM [tableName]
WHERE CAST([XMLColumnName] AS nvarchar(max)) LIKE N'%[textToSearchFor]%'

Hope this helps and happy coding!

Tagged as: , , Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a Reply

No trackbacks yet.

%d bloggers like this: