SQL:尝试将大字符串插入 varchar(max)

2021-09-10 00:00:00 sql tsql sql-server

我正在尝试做一个

INSERT INTO MYTBL
VALUES (CAST(SPACE(7997) + 'abcd' as nvarchar(max)) 

并且它不会超过 8000 字节不知道我做错了什么

and it does not go over 8000 bytes not sure what it is i am doing wrong

MYTBL 只有一列 (Col1 (nvarchar(max))

MYTBL only has one column (Col1 (nvarchar(max))

推荐答案

根据你最后遗漏的代码 ")"

based on your code you are missing last ")"

将您的代码修改为:

INSERT INTO MYTBL
VALUES (CAST(SPACE(7997) + 'abcd' as nvarchar(max))) 

另外,就像@datagod 所说的,您需要在连接之前将字符串转换/转换为 NVARCHAR(max).

additionaly just like @datagod said you need to convert/cast your strings as NVARCHAR(max) before concatenation.

你可以使用这个

INSERT INTO MYTBL
    VALUES ( CONVERT(NVARCHAR(MAX), SPACE(7997)) + CONVERT(NVARCHAR(MAX), 'abcd') )

相关文章