8

I'm running this SQL statement

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

5 Answers 5

10

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.

3

The column definitions for dbo.PricingProfileRuleSetCondition are too short for the data you're entering.

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.

Random thought: if you have declared columns as (n)varchar without a length, the length defaults to 1.

Saying that, why use dynamic SQL at all in this case? It would be a simple parameterised update.

2

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.

1

Just in case, if you need to safely truncate the data down to a length of 4000, look into the "left" or "right" functions.

0

try to minimize the length of the entry data or maximize the table column length

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.