即使所有参数都在限制范围内,字符串或二进制数据也会被截断错误

时间:2016-06-04 05:12:56

标签: sql sql-server stored-procedures

我有一个用于插入的存储过程。当我尝试通过传递这些值进行插入时,我收到此错误。

exec WorkDetail 'Insert',2,'2015-10-20','se31','entry','title','r','0','abh',

'client','proj','task','status','rea','module','2','4','stat','1'

这是存储过程。

    USE [OMS]
GO
/****** Object:  StoredProcedure [dbo].[WorkDetail]    Script Date: 06/04/2016 09:52:50 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[WorkDetail]
    @QueryType nvarchar(25),
    @ReportNo numeric(18,0),
    @ReportDate date,
    @EmpCode nvarchar(15),
    @Session nvarchar(50),
    @ReportTitle nvarchar(50),
    @ReportDesc nvarchar(Max),
    @ReportType numeric(18,0),
    @CreatedBy nvarchar(50),
    @ClientPlace nvarchar(50),
    @Project nvarchar(50),
    @Task nvarchar(50),
    @TaskStatus nvarchar(50),
    @Reason nvarchar(250),
    @Module nvarchar(50),
    @EntryFrom nvarchar(50),
    @EntryTo nvarchar(50),
    @Status nvarchar(25),
    @SQLReturn nvarchar(MAX) output 

AS
BEGIN
 SET NOCOUNT ON;
 Begin Transaction WorkDetails
 Declare @rcount int
 set @rcount=0
     if @QueryType='Insert'
         Begin
            if not exists(select * from WorkDetails where EmpCode=@EmpCode and ReportDate=@ReportDate and Session=@Session)                 
            Begin
                SET @ReportNo=(select ISNULL(MAX(ReportNo),0)+1 from WorkDetails)   
                Insert Into WorkDetails (ReportNo,ReportDate,EmpCode,Session,ReportTitle,ReportDesc,ReportType,Location,Project,Module,Task,TaskStatus,Reason,EntryFrom,EntryTo,Status,ReportTime,CreatedBy,CreatedDate,UpdatedBy,UpdateDate)
                Values(@ReportNo,@ReportDate,@EmpCode,@Session,@ReportTitle,@ReportDesc,@ReportType,@ClientPlace,@project,@Module,@Task,@TaskStatus,@Reason,@EntryFrom,@EntryTo,@Status,GETDATE(),@CreatedBy,GETDATE(),@CreatedBy,GETDATE())
                if @@ROWCOUNT>0
                    set @rcount=1
             End
            else
             set @rcount=-1
         End         
         if @rcount>0
    Begin
        commit transaction WorkDetails
        set @SQLReturn='Success'
    End 
    else if @rcount=-1
    Begin
        commit transaction WorkDetails
        set @SQLReturn='Already'
    End 
    Else
    Begin
        rollback transaction WorkDetails
        set @SQLReturn='Failure'
    End    
END

这是错误:

Msg 8152, Level 16, State 13, Procedure WorkDetail, Line 33 String or binary data would be truncated. The statement has been terminated.

我是sql的新手并且遇到了存储过程。我看到了此错误的其他问题,但我不明白哪个字段扩展了指定的限制

0 个答案:

没有答案