Home SQL - cast XML as nvarchar(max)
 I've got a problem with an SQL stored procedure. I need to generate a xml from a database. In my stored procedure, I collect all information and then my plan was to generate the XML file as I need it (see code). All transactions I need to report are loaded into the variable @transactionXml. It is of data type xml and can become quite big. SET @xmlOut += '' + cast(CAST(getdate() as date) as nvarchar(100)) + '' SET @xmlOut += '' + @noOfResults + '' SET @xmlOut += '' + cast(@fromDate as nvarchar(max)) + '' SET @xmlOut += '' + cast(@toDate as nvarchar(max)) + '' SET @xmlOut += '' + @minInvoiceNo + '' SET @xmlOut += '' + @maxInvoiceNo + '' SET @xmlOut += cast(@transactionXml as nvarchar(max)) SET @xmlOut += '' SELECT @xmlOut  When I try to cast the datatype to nvarchar(max) (as in the code section), the string is not complete and missing some information. It seems, that the string is cut after x-signs. Is there a way to cast the @transactionXml variable completely to text, so that I can use it in my @xmlOut statement?