开发者

How do I concatenate a large Text datatype in SQL Server

I have the next query:

select 'some text: ' + cast(description as varchar(8000)) + ' end text'
From descriptionTable

but my descript开发者_JAVA百科ion field it's larger than 8000 chars, so what can I do?, or do I have to make an application.

Thanks,

j2gl


Try this:

select 'some text: ' + cast(description as varchar(max)) + ' end text'
From descriptionTable

Because

declare @description varchar(8000) = REPLICATE('a', 8000)
select datalength('some text: ' + @description + ' end text')
select datalength('some text: ' + cast(@description as varchar(max) ) + ' end text')

Returns 8000 and 8020 respectively. Good luck.


When the the length is specified in declaring a VARCHAR variable or column, the maximum length allowed is still 8000. If the length is greater than 8000, you have to use the MAX specifier as the length.

Varchar(8000) stores a maximum of 8000 characters. Varchar(max) stores a maximum of 2 147 483 647 characters

Here you can find many answers regarding varchar size issues

so use max like this..

  select 'some text: ' + cast(description as varchar(max)) + ' end text'
  From descriptionTable
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜