Hi,
I have a table with a TEXT column and this column contains an XML document. I'm developing a TSQL stored procedure which reads the content of this column and accesses the values in the XML elements but I have a lot of problems...
1) How can I read the text column and store the value in a variable? I tried
declare @.a varchar(2048)
set @.a = (SELECT TEXT_COLUMN FROM MY_TABLE)
but it returns
Server: Msg 279, Level 16, State 3, Line 2
The text, ntext, and image data types are invalid in this subquery or aggregate expression.
I tried also with the READTEXT function but I just can't find how to store data read in a variable...
2) which length should I use for the VARCHAR variable which will store the data? Is it possible not to specify a length with SQL Server 7 or 2000?
Thanks!
Andrea
In SQL Server 7/2000 local variables cannot have a text data type. My advice would be if you know the length of the xml data is not going to be greater than 4000 chars (aprox.), use an NVARCHAR, that is going to allow you to be more flexible with your code.
Hope this helps,
Roberto Hernández-Pou
http://community.rhpconsulting.net
|||
you can try this
declare @.a varchar(8000)
set @.a = (SELECT convert(varchar(8000),text1) FROM texttest where text1like'some%' )
select @.a
You 'll be able to use text column in procedures but it has to converted to an accepted datatype in procedures
|||Just keep in mind that a decent sized XML document can easily go past 8000 characters causing any extra data to be truncated.|||
Hi,
thanks Gopi, Roberto and Whitney! Useful answers and comments!
Andrea