在phpMyAdmin中显示错误的存储过程结果

时间:2018-06-07 05:18:55

标签: c# mysql asp.net

我已经在phpMyAdmin(主机服务器)中部署了存储过程。但是当我执行查询时,我部署的过程结果出错了。但是同样的程序工作并在本地给出了完美的结果。日期字段显示错误的结果。任何人都可以建议解决方案吗?谢谢。 我的存储过程代码:

  BEGIN
    Declare eid varchar(25);
    Declare nextAppPers varchar(25);
    Declare ename varchar(40);
    Declare lid varchar(5);
    Declare leavefrm datetime;
    Declare leaveto datetime;
    Declare templeavefrm datetime;
    Declare templeaveto datetime;
    Declare frmtime varchar(10);
    Declare totime varchar(10);
    Declare stats varchar(25);
    Declare tempDate datetime;
    Declare pf datetime;
    Declare pt datetime;
    Declare phflag int; Declare dy int; Declare pgrpflag int;
    Declare sun int; Declare mon int; Declare tue int; Declare wed int; Declare thu int; Declare fri int; Declare sat int;
    DECLARE bDone INT DEFAULT FALSE; DECLARE xDone INT DEFAULT FALSE;

DECLARE RESLT_Cursor CURSOR FOR 
    select EmpId,EmpName,LeaveID,FromDate,ToDate,FromTime,ToTime,Status,NextApprovalPerson from LeaveApplication WHERE Status<>'Cancelled' and (MONTH(FromDate)= selMonth or MONTH(FromDate)= selMonth-1 or MONTH(FromDate)= selMonth+1) and Status<>'Rejected' and EmpId='20151203' order by ApplyDate,EmpId;

DECLARE RES_Cursor CURSOR FOR select PHFrom,PHTo from PHList;

DECLARE CONTINUE HANDLER FOR NOT FOUND SET bDone = TRUE;

    drop table IF EXISTS SplitLeaveApplication; 
    create table SplitLeaveApplication (EmpId varchar(25),EmpName varchar(40),LeaveID varchar(5),FromDate datetime,ToDate datetime,FromTime varchar(10),ToTime varchar(10),Status varchar(25),NextApprovalPerson varchar(25));

    OPEN RESLT_Cursor;

    read_loop: LOOP    
    FETCH RESLT_Cursor INTO eid,ename,lid,leavefrm,leaveto,frmtime,totime,stats,nextAppPers;
        IF bDone THEN       
            LEAVE read_loop;
        END IF;
            if leavefrm < leaveto then

                set templeavefrm='1900-01-01';
                set templeaveto='1900-01-01';
                set tempDate=leavefrm;

                while tempDate <= leaveto do

                    set phflag=0;
                    set pgrpflag=0;
                    set dy=(SELECT WEEKDAY(tempDate));

                        OPEN RES_Cursor;                    
                        rd_loop: LOOP
                            FETCH RES_Cursor INTO pf,pt;                                                        
                            if pf<=tempDate and pt>=tempDate then                       
                                set phflag=1;
                            end if;                             

                            IF bDone THEN
                                LEAVE rd_loop;
                            END IF;
                        END LOOP rd_loop;
                        CLOSE RES_Cursor;
                        set bDone=False;                   

                    BLOCK3: BEGIN
                    DECLARE RESLT2_Cursor CURSOR FOR    
                    select Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday from Paygroup where Paygroup=(select Paygroup from Employee where EmpId=eid);
                    OPEN RESLT2_Cursor;                                 
                    FETCH RESLT2_Cursor INTO sun,mon,tue,wed,thu,fri,sat;                       
                        if sun=1 and dy=6 then                      
                            set pgrpflag=1;
                        end if;
                        if mon=1 and dy=0 then                  
                            set pgrpflag=1;
                        end if;
                        if tue=1 and dy=1 then                  
                            set pgrpflag=1;
                        end if;
                        if wed=1 and dy=2 then                  
                            set pgrpflag=1;
                        end if;
                        if thu=1 and dy=3 then                  
                            set pgrpflag=1;
                        end if;
                        if fri=1 and dy=4 then                  
                            set pgrpflag=1;
                        end if;
                        if sat=1 and dy=5 then                  
                            set pgrpflag=1;
                        end if;                                                 
                    CLOSE RESLT2_Cursor;    
                    END BLOCK3;


                    if phflag=0 and pgrpflag=0 then                                         
                        if templeavefrm='1900-01-01' then                       
                            set templeavefrm=tempDate;
                            set templeaveto=tempDate;                       
                        else                        
                            set templeaveto=tempDate;
                        end if;

                        if tempDate=leaveto then                        
                            insert into SplitLeaveApplication (EmpId,EmpName,LeaveID,FromDate,ToDate,FromTime,ToTime,Status,NextApprovalPerson) values (eid,ename,lid,templeavefrm,templeaveto,frmtime,totime,stats,nextAppPers);                       
                        end if;                                                 
                    else                                        
                        if templeavefrm<>'1900-01-01' and templeaveto<>'1900-01-01' then                        
                            insert into SplitLeaveApplication (EmpId,EmpName,LeaveID,FromDate,ToDate,FromTime,ToTime,Status,NextApprovalPerson) values (eid,ename,lid,templeavefrm,templeaveto,frmtime,totime,stats,nextAppPers);
                        end if;
                        set templeavefrm='1900-01-01';
                        set templeaveto='1900-01-01';
                    end if;

                    set tempDate=(SELECT DATE_ADD(tempDate, INTERVAL 1 day));   

                end while;  
            else            
                insert into SplitLeaveApplication (EmpId,EmpName,LeaveID,FromDate,ToDate,FromTime,ToTime,Status,NextApprovalPerson) values (eid,ename,lid,leavefrm,leaveto,frmtime,totime,stats,nextAppPers);
            end if;


    END LOOP read_loop;
    CLOSE RESLT_Cursor; 
END

请参阅我的本地结果和phpAdminresult的图片。 Local db result

phpMyAdmin Result

0 个答案:

没有答案