我有下面的查询,其中我插入临时表,当我尝试运行查询sql投掷二进制或字符串数据将被截断。但实际上我的数据属于nvarchar(400)
列的PhoneModel
定义范围。
CREATE TABLE #orders
(
quoteHeaderId INT,
PhoneModel nvarchar(400)
)
INSERT INTO #orders(quoteHeaderId, PhoneModel)
SELECT qh.QuoteHeaderId,
(Select ph.ModelName + ','
FROM t_handsetQuote h2
INNER JOIN t_PhoneAudit t1 on t1.PhoneAuditId = h2.QuotePhoneAuditId
INNER JOIN t_phoneModel ph on t1.phoneModelid = ph.phoneModelid
where qh.QuoteHeaderId = h2.QuoteHeaderId
FOR XML PATH('')
) AS PhoneModel
FROM t_QuoteHeader qh
INNER JOIN t_handsetQuote h on qh.QuoteHeaderId = h.QuoteHeaderId
INNER JOIN t_CustomerAdditionalInformation ch on qh.CustomerId = ch.CustomerId
and keyName ='SendUpdatesByEmail' AND ch.value = 'yes'
答案 0 :(得分:1)
我认为nvarchar(400)
无法处理您插入的字符串的长度。
如何将PhoneModel nvarchar(400)
更改为PhoneModel varchar(MAX)
答案 1 :(得分:0)
运行没有insert语句的select查询,并检查len
的{{1}}。记录可能会有所不同。
运行您的查询并提供反馈。
答案 2 :(得分:0)
最容易看出导致问题的原因是使用select ... into:
SELECT qh.QuoteHeaderId,
(Select ph.ModelName + ','
FROM t_handsetQuote h2
INNER JOIN t_PhoneAudit t1 on t1.PhoneAuditId = h2.QuotePhoneAuditId
INNER JOIN t_phoneModel ph on t1.phoneModelid = ph.phoneModelid
where qh.QuoteHeaderId = h2.QuoteHeaderId
FOR XML PATH('')
) AS PhoneModel
into #orders
FROM t_QuoteHeader qh
INNER JOIN t_handsetQuote h on qh.QuoteHeaderId = h.QuoteHeaderId
INNER JOIN t_CustomerAdditionalInformation ch on qh.CustomerId = ch.CustomerId
and keyName ='SendUpdatesByEmail' AND ch.value = 'yes'
然后通过命令len(PhoneModel)desc
来检查创建的表