| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1599 人关注过本帖
标题:求高手指点,原来存储过程执行正常的,现在报错了
只看楼主 加入收藏
笑罗汉
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2015-6-11
收藏
 问题点数:0 回复次数:7 
求高手指点,原来存储过程执行正常的,现在报错了
USE [CardManage]
GO
/****** Object:  StoredProcedure [dbo].[Work_DataTransact]    Script Date: 06/09/2015 15:07:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

--'00000000-0000-0000-0000-000000000000'

ALTER PROCEDURE [dbo].[Work_DataTransact]
    -- Add the parameters for the stored procedure here
    @WorkDatetime Datetime--排班单内的某一天
AS
BEGIN
    --临时表#WorkEmplClass 要处理的人员及班次
    --临时表#WorkRecord    要处理人员的数据
    --临时表#WorkEmplRecord 处理后的数据存入此表

    --处理考勤每一天的数据
    Declare @NextDay Bit    -- 代表有跨天
    Declare @OnDutyMin Int,@OffDutyMin Int,@OverStartTimeMin Int,@OverEndTimeMin Int
    Declare @RestTime1StartMin Int,@RestTime1EndMin Int,@RestTime2StartMin Int,@RestTime2EndMin Int,@RestMin Int
    Declare @OnDuty Datetime,@OffDuty Datetime,@OnDutyAdvanceTime Datetime,@OnDutyDelayTime Datetime,@OffDutyAdvanceTime Datetime,@OffDutyDelayTime Datetime
    /*
    Declare @ClassType NVarChar(2),@ClassName Varchar(50),@AdvanceOnDutyMin Int,@LateMinAbsence Int,@AllowLateMin Int,@EarlyMinAbsence Int,@DelayOffDutyMin Int,@AllowEarlyMin Int,@RestTime1Start Datetime,@RestTime1End Datetime,@RestTime2Start Datetime,@RestTime2End Datetime,@RestTimeAllowLDMin Int,@OverStartTime Datetime,@OverEndTime Datetime,@OverMinValid Int
    Declare @Remark Varchar(50)
    Declare @ClassNo uniqueidentifier,@WorkHours Numeric(10,1)
    Declare @OverStarttimeEstimate varchar(5), @OverEndtimeEstimate varchar(5),@OverHoursEstimate Numeric(10,1)
    */
    Declare @ClassType NVarChar(20),@ClassName Varchar(50),@AdvanceOnDutyMin Int,@LateMinAbsence Int,@AllowLateMin Int,@EarlyMinAbsence Int,@DelayOffDutyMin Int,@AllowEarlyMin Int,@RestTime1Start Datetime,@RestTime1End Datetime,@RestTime2Start Datetime,@RestTime2End Datetime,@RestTimeAllowLDMin Int,@OverStartTime Datetime,@OverEndTime Datetime,@OverMinValid Int
    Declare @Remark Varchar(50)
    Declare @ClassNo uniqueidentifier,@WorkHours Numeric(20,2)
    Declare @OverStarttimeEstimate varchar(15), @OverEndtimeEstimate varchar(15),@OverHoursEstimate Numeric(20,2)
   
    If @WorkDatetime>Getdate() goto execend
    Select Top 1 @ClassNo=ClsNo From (Select Distinct ClsNo From #WorkEmplClass)A
    While @@rowcount>0
    Begin
        Select @ClassType=ClassType,@ClassName=ClassName,@OnDuty=OnDuty,@OffDuty=OffDuty,@AdvanceOnDutyMin=AdvanceOnDutyMin,@LateMinAbsence=LateMinAbsence,@AllowLateMin=AllowLateMin,@EarlyMinAbsence=EarlyMinAbsence,@DelayOffDutyMin=DelayOffDutyMin,@AllowEarlyMin=AllowEarlyMin,@RestTime1Start=RestTimeStart,@RestTime1End=RestTimeEnd,@OverStartTime=OverStartTime,@OverEndTime=OverEndTime,@OverMinValid=OverMinValid From Work_Class Where SerialNo=@ClassNo

        --清空本天内所操作人员的考勤记录
        
        Select @Remark=HolidayName From Work_Holiday A Inner Join System_Serial B On A.SerialNo=B.SerialNo Where Status=1 And @WorkDatetime Between StartDate And EndDate
        If @@Rowcount>0        --节假日
            Insert #WorkEmplRecord Select ItemCode,EmplCode,EmplName,'节假日',@WorkDatetime,'','',0,0,0,0,'',0,0,@Remark,0 From #WorkEmplClass Where ClsNo=@ClassNo
        Else IF @ClassType ='休息'
            Insert #WorkEmplRecord Select ItemCode,EmplCode,EmplName,'休息日',@WorkDatetime,'','',0,0,0,0,'',0,0,@ClassName,0 From #WorkEmplClass Where ClsNo=@ClassNo
        Else IF @ClassType ='工作'
        Begin
            --取出上班时间占当天的分钟数
            Set @OnDutyMin= datediff(n,'00:00:00',Convert(Varchar(8),@OnDuty,108))   
            --取出下班时间占当天的分钟数
            Set @OffDutyMin= datediff(n,'00:00:00',Convert(Varchar(8),@OffDuty,108))
            --取出加班开始时间占当天的分钟数
            Set @OverStartTimeMin= datediff(n,'00:00:00',Convert(Varchar(8),@OverStartTime,108))
            --取出加班结束时间占当天的分钟数
            Set @OverEndTimeMin= datediff(n,'00:00:00',Convert(Varchar(8),@OverEndTime,108))
            --取出第一休息开始时间占当天的分钟数
            Set @RestTime1StartMin= datediff(n,'00:00:00',Convert(Varchar(8),@RestTime1Start,108))   
            --取出第一休息结束时间占当天的分钟数
            Set @RestTime1EndMin= datediff(n,'00:00:00',Convert(Varchar(8),@RestTime1End,108))

            
            If @RestTime1StartMin<=@RestTime1EndMin
                Set @RestMin=@RestTime1EndMin-@RestTime1StartMin
            Else
                Set @RestMin=@RestTime1EndMin+1440-@RestTime1StartMin

            Set @NextDay=0
            --下班分钟小于或等于上班分钟时表示为跨天,则增加一天分钟,即1440
            If @OnDutyMin>=@OffDutyMin    --20:00 07:00 --00:00 00:00|12:00 12:00
            Begin
                Set @OffDutyMin=@OffDutyMin+1440
                Set @NextDay=1
            End
            --取出本天的上班时间:2008-11-10 07:00
            Set @OnDuty=Dateadd(n,@OnDutyMin+@AllowLateMin,@WorkDatetime)
            --取出本天的下班时间:2008-11-10 17:00
            Set @OffDuty=Dateadd(n,@OffDutyMin-@AllowEarlyMin,@WorkDatetime)
            --取出上下班的提前延后分钟
            Set @OnDutyAdvanceTime=Dateadd(n,@OnDutyMin-@AdvanceOnDutyMin,@WorkDatetime)
            Set @OnDutyDelayTime=Dateadd(n,@OnDutyMin+@LateMinAbsence,@WorkDatetime)
            Set @OffDutyAdvanceTime=Dateadd(n,@OffDutyMin-@EarlyMinAbsence,@WorkDatetime)
            Set @OffDutyDelayTime=Dateadd(n,@OffDutyMin+@DelayOffDutyMin,@WorkDatetime)

            --有加班设置
            If @OverStartTimeMin>0 Or @OverEndTimeMin>0
            Begin
--select @OffDutyDelayTime,@NextDay,@OverEndTimeMin,@OverStartTimeMin,@OffDutyMin
                If @NextDay=0 And @OverEndTimeMin>@OverStartTimeMin And @OverStartTimeMin>=@OffDutyMin
                Begin
                    Set @OverStartTime=Dateadd(n,@OverStartTimeMin+@OverMinValid,@WorkDatetime)   
                    Set @OverEndTime=Dateadd(n,@OverEndTimeMin,@WorkDatetime)
--select @OverEndTimeMin,@WorkDatetime
                End
                Else
                Begin
                    If @OverEndTimeMin>=@OverStartTimeMin
                        Set @OverStartTime=Dateadd(n,@OverStartTimeMin+@OverMinValid+1440,@WorkDatetime)
                    Else
                        Set @OverStartTime=Dateadd(n,@OverStartTimeMin+@OverMinValid,@WorkDatetime)
                    Set @OverEndTime=Dateadd(n,@OverEndTimeMin+1440,@WorkDatetime)
                End
                Set @OffDutyDelayTime=@OverEndTime
            End
            --加班预计
            Set @OverStarttimeEstimate=Convert(char(5),DateAdd(n,-@OverMinValid,@OverStartTime),108)
            Set @OverEndtimeEstimate=Convert(Varchar(5),@OverEndTime,108)
            Set @OverHoursEstimate=0

            Set @WorkHours=Cast(ROUND(Cast(@OffDutyMin-@OnDutyMin-@RestMin As Numeric(10,1))/60,1)As Numeric(10,1))
--select @OffDutyAdvanceTime , @OffDutyDelayTime
            --只保留要处理的天的数据
            Select ItemCode,WorkDatetime Into #WorkRecordTmp From #WorkRecord Where WorkDatetime Between @OnDutyAdvanceTime and @OffDutyDelayTime
            --取出每个人在上班段最早的时间及下班段最迟的时间
            Insert #WorkEmplRecord
            Select ItemCode,EmplCode,EmplName,@ClassName,@WorkDatetime,OnDutyTime,OffDutyTime,@WorkHours,
            --上班分数等于下班时间减上班时间减休息分钟减迟到及早退分钟
            WorkDutyHours=Case When OnDutyTime!='' and OffDutyTime!='' Then Cast(ROUND(Cast(@OffDutyMin-@OnDutyMin-@RestMin-LateMin-EarlyMin As Numeric(10,1))/60,1)As Numeric(10,1)) Else 0 End,LateMin,EarlyMin,Case When WorkOver=0 Then '' Else Convert(Char(5),Dateadd(n,-@OverMinValid,@OverStartTime),108) End,WorkOver,0,'',0 From
            (
            Select C.ItemCode,C.EmplCode,EmplName,isnull(Convert(Char(5),OnDutyTime,108),'')OnDutyTime,isnull(Convert(Char(5),OffDutyTime,108),'')OffDutyTime
            --迟到:当上班时间为空或实际上班时间小于或等于规定的上班时间时表示无迟到
            ,LateMin=Case When OnDutyTime Is Null Or OnDutyTime<=@OnDuty Then 0 Else Datediff(n,@OnDuty,OnDutyTime)+@AllowLateMin End
            --早退:当下班时间为空或实际上班时间小于或等于规定的上班时间时表示无迟到
            ,EarlyMin=Case When OffDutyTime Is Null Or @OffDuty<=OffDutyTime Then 0 Else abs(Datediff(n,@OffDuty,OffDutyTime)) End
            ,WorkOver=Case When OffDutyTime Between @OverStartTime And @OverEndTime Then Datediff(n,@OverStartTime,OffDutyTime)+@OverMinValid Else 0 End
             From #WorkEmplClass C Left Outer Join
            (Select ItemCode,Min(WorkDatetime)OnDutyTime From #WorkRecordTmp Where WorkDatetime Between @OnDutyAdvanceTime and @OnDutyDelayTime Group By ItemCode)A On C.ItemCode=A.ItemCode Left Outer Join
            (Select ItemCode,Max(WorkDatetime)OffDutyTime From #WorkRecordTmp Where WorkDatetime Between @OffDutyAdvanceTime and @OffDutyDelayTime Group By ItemCode)B On C.ItemCode=B.ItemCode
        Where ClsNo=@ClassNo)A

        End

        --将加班的记录存进加班表
        Delete Work_RecordOver Where OverTimeDate=@WorkDatetime And ItemCode In(Select ItemCode From #WorkEmplClass Where ClsNo=@ClassNo)
        Insert Work_RecordOver Select ItemCode,EmplCode,EmplName,WorkDate,@OverStarttimeEstimate,@OverEndtimeEstimate,@OverHoursEstimate,'',WorkOverStart,OffDutyTime,WorkOverMins,'',0 From #WorkEmplRecord Where WorkDate=@WorkDatetime And ItemCode In(Select ItemCode From #WorkEmplClass Where ClsNo=@ClassNo) And WorkOverMins>0

        Delete #WorkEmplClass Where ClsNo=@ClassNO
        Select Top 1 @ClassNo=ClsNo From (Select Distinct ClsNo From #WorkEmplClass)A
    End

execend:   

End

现在执行报错信息:
消息 8152,级别 16,状态 14,过程 Work_DataTransact,第 130 行
将截断字符串或二进制数据。
语句已终止。
搜索更多相关主题的帖子: procedure Object 
2015-06-11 10:44
林月儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:湖南
等 级:版主
威 望:138
帖 子:2277
专家分:10647
注 册:2015-3-19
收藏
得分:0 
--将加班的记录存进加班表
        Delete from Work_RecordOver Where OverTimeDate=@WorkDatetime And ItemCode In(Select ItemCode From #WorkEmplClass Where ClsNo=@ClassNo)
        Insert into Work_RecordOver Select ItemCode,EmplCode,EmplName,WorkDate,@OverStarttimeEstimate,@OverEndtimeEstimate,@OverHoursEstimate,'',WorkOverStart,OffDutyTime,WorkOverMins,'',0 From #WorkEmplRecord Where WorkDate=@WorkDatetime And ItemCode In(Select ItemCode From #WorkEmplClass Where ClsNo=@ClassNo) And WorkOverMins>0

剑栈风樯各苦辛,别时冰雪到时春
2015-06-11 20:05
笑罗汉
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2015-6-11
收藏
得分:0 
谢谢回复!
不过这存过程对加班表操作用delete和delete from是一样的,问题依旧存在。
2015-06-12 09:08
hu9jj
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:红土地
等 级:贵宾
威 望:400
帖 子:11857
专家分:43421
注 册:2006-5-13
收藏
得分:0 
出错的行在哪儿?应该标出来才方便大家分析。

活到老,学到老!http://www.(该域名已经被ISP盗卖了)E-mail:hu-jj@
2015-06-16 06:42
笑罗汉
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2015-6-11
收藏
得分:0 
出错提示在130行,就是这语句的最后。存储以前都是正常运行的,最近才报错,代码没有修改过,数据库空间也足够的。
    Select C.ItemCode,C.EmplCode,EmplName,isnull(Convert(Char(5),OnDutyTime,108),'')OnDutyTime,isnull(Convert(Char(5),OffDutyTime,108),'')OffDutyTime
             --迟到:当上班时间为空或实际上班时间小于或等于规定的上班时间时表示无迟到
            ,LateMin=Case When OnDutyTime Is Null Or OnDutyTime<=@OnDuty Then 0 Else Datediff(n,@OnDuty,OnDutyTime)+@AllowLateMin End
             --早退:当下班时间为空或实际上班时间小于或等于规定的上班时间时表示无迟到
            ,EarlyMin=Case When OffDutyTime Is Null Or @OffDuty<=OffDutyTime Then 0 Else abs(Datediff(n,@OffDuty,OffDutyTime)) End
             ,WorkOver=Case When OffDutyTime Between @OverStartTime And @OverEndTime Then Datediff(n,@OverStartTime,OffDutyTime)+@OverMinValid Else 0 End
              From #WorkEmplClass C Left Outer Join
             (Select ItemCode,Min(WorkDatetime)OnDutyTime From #WorkRecordTmp Where WorkDatetime Between @OnDutyAdvanceTime and @OnDutyDelayTime Group By ItemCode)A On C.ItemCode=A.ItemCode Left Outer Join
             (Select ItemCode,Max(WorkDatetime)OffDutyTime From #WorkRecordTmp Where WorkDatetime Between @OffDutyAdvanceTime and @OffDutyDelayTime Group By ItemCode)B On C.ItemCode=B.ItemCode
         Where ClsNo=@ClassNo)A
2015-06-16 09:24
volte
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:69
帖 子:1167
专家分:1316
注 册:2004-12-19
收藏
得分:0 
根据报错提示,截断字符串或二进制数据;
说明在 insert 表里,有字段写入值超过字段设置的最大字符串;

大家都是朋友,有空就来坐坐!
2015-06-23 09:27
博学硬汉
Rank: 1
来 自:杭州
等 级:新手上路
帖 子:1
专家分:0
注 册:2015-6-25
收藏
得分:0 
问题解决了吗?

杭州博学教育大数据,oracle,cisso,redhat, liunx培训专家
电话:057128976118
2015-06-25 09:32
快速回复:求高手指点,原来存储过程执行正常的,现在报错了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024780 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved