开发者

How to assign large concatenated string in sql server

开发者 https://www.devze.com 2023-03-24 16:26 出处:网络
How to assign a large text more than 8000 characters in SQL serve开发者_运维百科r Thanks, Vara Prasad.MUse one of the max types but beware that any intermediate expressions will be varchar(8000) (or

How to assign a large text more than 8000 characters in SQL serve开发者_运维百科r

Thanks, Vara Prasad.M


Use one of the max types but beware that any intermediate expressions will be varchar(8000) (or nvarchar(4000)) unless they involve the (n)varchar(max) type

DECLARE @maxtype varchar(max)

--on the right, never above 8000
SET @maxtype = REPLICATE('a', 6000) + REPLICATE('b', 6000)
SELECT LEN(@maxtype) --8000

--here, there is a max on the right
SET @maxtype = REPLICATE(CAST('a' AS varchar(max)), 6000) + REPLICATE('b', 6000)
SELECT LEN(@maxtype) --12000


Use a VARCHAR(MAX) or NVARCHAR(MAX) data type.

0

精彩评论

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