ms sql xml data type convert to text ms sql xml data type convert to text sql-server sql-server

ms sql xml data type convert to text


A simple cast will suffice:

select cast(XMLCol as nvarchar(max)) as XMLCol 

Or for non-unicode:

select cast(XMLCol as varchar(max)) as XMLCol 

You can't convert explicitly to a 'text' data type.

I've added the as XMLCol to ensure that the converted data has the the same name as the column. You needn't have this, of course.

EDIT:

A few links. You are encouraged to use nvarchar(max) instead of text regardless. Microsoft have said they will be deprecating these types in future releases. nvarchar(max) ought to offer you 2GB:

http://www.petefreitag.com/item/734.cfm

http://www.teratrax.com/articles/varchar_max.html

http://msdn.microsoft.com/en-us/library/ms187752(v=SQL.90).aspx


SELECT CAST(YourXMLColumn as nvarchar(max))    FROM YourTable


I just tried the follwing solution and yes, you do need the as XMLCol

select cast(XMLCol as nvarchar(max)) as XMLCol