Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sql exception : The statement has been terminated

Tags:

sql

sql-server

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

like image 334
Maged Samaan Avatar asked May 04 '11 08:05

Maged Samaan


People also ask

Why a statement is terminated in SQL?

Using ApexSQL Refactor, all SQL statements can be terminated with a semicolon to prevent syntax mistakes in future versions of SQL Server and format SQL code and scripts to comply with the SQL formatting rules.

How is a SQL statement terminated?

By default, SQL statements are terminated with semicolons.

How do you fix string or binary data would be truncated The statement has been terminated?

To fix this error, patch to SQL Server 2016 SP2, CU6 or newer (including SQL Server 2017), and then turn on trace flag 460. You can enable it at the query level or at the server level.

How ignore string or binary data would be truncated?

To avoid this error and to insert the string with truncation, use the ANSI_WARNINGS option. On setting ANSI_WARNINGS to OFF, the error message will not be displayed and the data will be automatically truncated to the length of the destination column and inserted.


1 Answers

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.

like image 192
Pleun Avatar answered Nov 12 '22 21:11

Pleun