Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if SQL Server 2005 XML field is empty

I just did this:

Delete FROM MyTable WHERE ScopeValue = "" 
Delete FROM G_Scope WHERE ScopeValue is ''
Delete FROM G_Scope WHERE ScopeValue = empty
Delete FROM G_Scope WHERE ScopeValue is empty

I want to delete all rows with xml field (not nullable) where ScopeValue column has empty entries means zero chars.

Anyone knows?

like image 461
msfanboy Avatar asked Jun 25 '10 11:06

msfanboy


People also ask

How do I check if an XML tag exists in SQL?

The exist() method in the WHERE clause returns 1 (True) if the XML does not include any < Specifications > element. Note the use of the not() function (XQuery). The sql:column() function (XQuery) function is used to bring in the value from a non-XML column. This query returns an empty rowset.

How do I check if a record is empty in SQL?

SELECT * FROM yourTableName WHERE yourSpecificColumnName IS NULL OR yourSpecificColumnName = ' '; The IS NULL constraint can be used whenever the column is empty and the symbol ( ' ') is used when there is empty value.


1 Answers

Try this:

 DELETE FROM dbo.G_Scope WHERE ScopeValue IS NULL

The SQL Server column would be NULL is if contains no value.

The other possibility would be that the XML is not NULL, but contains an empty string as its value. For that, use this command:

-- The DATALENGTH of an empty XML column is 5
SELECT * FROM dbo.G_Scope WHERE DATALENGTH(ScopeValue) = 5

Does that show you the rows you're interested in?

like image 100
marc_s Avatar answered Oct 25 '22 03:10

marc_s