sql 异常:语句已终止
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5880526/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
sql exception : The statement has been terminated
提问by mBotros
I'm running this SQL statement
我正在运行这个 SQL 语句
exec sp_executesql
N'UPDATE dbo.PricingProfileRuleSetCondition
SET RuleGroup = @p0,
JoinClause = @p1,
ColumnName = @p2,
Operator = @p3,
Value = @p4,
RuleSetId = @p5
WHERE Id = @p6',
N' @p0 int,
@p1 nvarchar(4000),
@p2 nvarchar(4000),
@p3 nvarchar(4000),
@p4 nvarchar(4000),
@p5 bigint,
@p6 bigint'
,
@p0=0,
@p1=N'And',
@p2=N'DMS.Finance.Entities.PartnerAccountTransactionAmountType.EnglishName',
@p3=N'eq',
@p4=N'dsaf',
@p5=4,
@p6=6
and I'm getting
我得到
Msg 8152, Level 16, State 2, Line 1
String or binary data would be truncated.
The statement has been terminated.
help,please
请帮忙
回答by Pleun
A string you are trying to insert is longer than the max nr of charachters. E.g. like a string with 4001 charachters in a varchar(4000) datatype.
您尝试插入的字符串比字符的最大 nr 长。例如,在 varchar(4000) 数据类型中包含 4001 个字符的字符串。
回答by gbn
The column definitions for dbo.PricingProfileRuleSetCondition are too short for the data you're entering.
dbo.PricingProfileRuleSetCondition 的列定义对于您输入的数据来说太短了。
So one of the values of @p1, @p2, @p3, @p4 is too long for the relevant column, despite your declaration of parameters as nvarchar(4000). Personally, I'd match parameter datatype and length to the columns.
因此,@p1、@p2、@p3、@p4 的值之一对于相关列来说太长,尽管您将参数声明为 nvarchar(4000)。就个人而言,我会将参数数据类型和长度与列匹配。
Random thought: if you have declared columns as (n)varchar without a length, the length defaults to 1.
随机想法:如果您将列声明为 (n)varchar 没有长度,则长度默认为 1。
Saying that, why use dynamic SQL at all in this case? It would be a simple parameterised update.
话虽如此,为什么在这种情况下完全使用动态 SQL?这将是一个简单的参数化更新。
回答by ariel
One of your columns data type is not big enough for the string you are assigning. You need to increase the data max length or truncate the string.
您的列数据类型之一对于您分配的字符串不够大。您需要增加数据最大长度或截断字符串。
It's probably ColumnName, which you are trying to assign a string of length 69.
它可能是 ColumnName,您正在尝试为其分配长度为 69 的字符串。
回答by Superbeard
Just in case, if you need to safely truncate the data down to a length of 4000, look into the "left" or "right" functions.
以防万一,如果您需要安全地将数据截断到 4000 的长度,请查看“左”或“右”函数。