Identifying empty XML Values

Something I was tasked with recently was identifying rows in a table which contained empty xml strings.  Because the column is of XML data types I couldn’t simple check WHERE column = NULL or ‘’ so instead I used the length function to determine the length of data in my XML attribute, an example of which can be found below.


   1: SELECT   LEN(HistoricalParameterValues.value('(/ReportParameters)[1]','varchar(max)')) as L

   2:          ,HistoricalParameterValues 




As you can see by using the the xml.value method against my report parameter attribute and wrapping this in the LEN() function allows me to then filter my records to those where the length equals zero.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s