Subscribe Now: Feed Icon

Friday, January 28, 2011

Database Queries Trick 1: Query XML

I was playing around with ESRI sde tables and one of the column was a XML column I wanted to query, like this:

  1. where (Definition like '%<blah>%</blah>%')

Will cause an error:

  1. Msg 8116, Level 16, State 1, Line 2
  2. Argument data type xml is invalid for argument 1 of like function.

But:

  1. where (cast(Definition as varchar(max)) like '%<blah>%</blah>%')

Works like a charm!

Resources:

ASP.Net Forum: Argument data type xml is invalid for argument 1 of like function

 

Keywords: XML, SQL, SQL Server 2008, Error

IceRocket Tags: ,,,