Click here to Skip to main content
16,021,169 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
>Msg 305, Level 16, State 1, Procedure ViewMaintenance, Line 9<br />
The XML data type cannot be compared or sorted, except when using the IS NULL operator.


This the Code:

SQL
GO
CREATE PROCEDURE ViewMaintenance
	@FormID nchar(5),
	@SupplierID nchar(5),
	@PlateNumber nchar(6),
	@ServiceForm xml
AS
	SET NOCOUNT ON;
	
	Select FormID, SupplierID, PlateNumber, ServiceForm
	From Maintenance
	Where FormID = @FormID AND SupplierID = @SupplierID
	AND PlateNumber = @PlateNumber AND ServiceForm = @ServiceForm
GO
Posted
Updated 12-Jun-12 22:29pm
v2

From MSDN http://msdn.microsoft.com/en-us/library/ms187107(v=sql.90).aspx[^]

The following limitations apply to the xml data type:<br />
 •Cannot be used as a subtype of a sql_variant instance<br />
 •Does not support casting or converting to either text or ntext.<br />
 •Does not support the following column and table constraints: <br />
◦PRIMARY KEY/ FOREIGN KEY<br />
 ◦UNIQUE<br />
 ◦COLLATE<br />
 XML provides its own encoding. Collations apply to string types only. The xml data type is not a string type. However, it does have string representation and allows casting to and from string data types.<br />
 ◦RULE<br />
 <br />
•Cannot be compared or sorted. This means an xml data type cannot be used in a GROUP BY statement.


You need to convert to another data type and then perform the operation.
But generally xml data type is quite large. Using them in Group BY, CONVERT etc tend to take more memory. Do you really want to have the column in the select statement.
You can perform a distinct select on the other columns, and find the primary key and then connect to this table to get the xml column.
Please check whether that option performs better.
 
Share this answer
 
This usually happens when you are comparing XML datatype. when you select the XML value, it returns the word NULL, it means that there is no value. If you inserted the value NULL into an XML datatype and then selected it, you'd get a blank value returned.

So, what this means is that you need to change you comparison from = NULL to IS NULL.

http://sqlserverlearner.com/2012/the-xml-data-type-cannot-be-compared-or-sorted-except-when-using-the-is-null-operator[^]

http://www.sqlservercentral.com/Forums/Topic582804-149-1.aspx[^]
 
Share this answer
 
Comments
EvanJo 13-Jun-12 4:37am    
Thankyou! It work, I just Change the ServiceForm = @ServiceForm to ServiceForm IS NULL. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900