Thursday, 15 July 2010

Use a LIKE statement on SQL Server XML Datatype -


If you have a varchar field, then you can easily find a table with SELECT * where the column '% test% 'Can to see if there is a fixed string in that column.

How do you do this for the XML type?

I have the following which is the only 'row' node but I have to search within that node

  from the webpage where the data is located. Axis ('/ PageContent / Text') = 1  

You do it very easily Should be enabled in:

  SELECT * FROM WebPageContent WHERE data.value (' 

.value method gives you real value (/ Page content / text) [1] ',' varchar (100) ')' xyz% ', and you can define it to be returned as VARCHAR (), which you will later add to a statement Can check with.

You note, this is not going to be very fast, so if you have some fields in your XML that you need to inspect a lot, you can do the following:

  • Create an archived function that receives XML and returns the value you are viewing as VARCHAR ()
  • Define a new math field on your table that Call this function, and it's a purse With this, you create std columns

With it, you basically create "remove" part of MFML in a calculated field, make it sustainable, and then you can use it very efficiently Can search (HECK: You can even do that area!).

Mark


No comments:

Post a Comment