How to set 9000 characters to nvarchar (max)

I need to set 9000 chars in nvarchar variable

declare @inXMLRequest xml

declare @insertsql nvarchar(max)

set @insertsql='--------9000 characters--------'
EXEC sp_executesql   @insertsql,
                   N'@inXMLRequest XML OUTPUT', 
                     @inXMLRequest OUTPUT 
print @insertsql

      

But NVARCHAR only accepts 5000 characters, how to set 9000 characters in NVARCHAR variable?

+2


source to share


3 answers


Thanks everyone,

Applies to use SP_Executesql directly We Execute nvarchar variable

Above we prepare @insertsql nvarchar variable over 8000 characters and it gives sp_executesql like this

EXEC sp_executesql @insertsql, N '@inXMLRequest XML OUTPUT', @inXMLRequest OUTPUT



The above query has been replaced by the below query

Exec ('DeClare @inXMLRequest XML SET @inXMLRequest='------above 8000 characters---')

      

Finally, we will execute this nvarchar line and select put

0


source


if you write a small program that tries to do the same outside of control studio, you should be able to do it.

unfortunately for some reason this cannot be done using the insert statement in control studio. there is a limit of 4 thousand that you put in the management studio.



I am doing inserts before, i.e. we insert the 4k symbols first, then the next 4k symbols, etc.

+1


source


I'm not sure, but you cannot store such long lines in a varchar. the string must fit into the db page. Varchar fields are stored on the same page where the string is stored. the page is usually less than 8192 bytes (depending on the db system)

there are some exceptions like blob fields that are not stored on the same page of the line.

you must use a different datatype like text / blob / image.

nvarchar 9000 is by the way. it is impossible to allocate 18000 bytes that do not fit into the page. this is the reason for the 4000 char limit.

+1


source







All Articles