简体   繁体   English

SSMS存储过程未显示截止日期的记录

[英]SSMS Stored procedure not showing records that fall on end date

I have a stored procedure that takes in two parameters: start date ( @SDate ) and end date ( @EDate ), after which it outputs a summary of data between the two dates. 我有一个存储过程,它有两个参数:开始日期( @SDate )和结束日期( @EDate ),之后它输出两个日期之间的数据摘要。

However, it does not show records that falls on the @EDate . 但是,它不显示落在@EDate上的@EDate

This is my code: 这是我的代码:

DECLARE TidCursor SCROLL CURSOR
FOR 
    SELECT DISTINCT  
        A.TID, P.ProjGroup, A.Location, P.MainSubCon
    FROM 
        [PRT].[dbo].[Personnel] P,[PRT].[dbo].[Attendance] A 
    WHERE 
        A.TID = P.TID 
        AND (A.Timein BETWEEN @SDate AND @EDate) 
        AND (A.Timeout BETWEEN @SDate AND @EDate) 
        AND (A.Timein IS NOT NULL AND A.timeout IS NOT NULL)
    ORDER BY 
        A.TID ASC   

OPEN TidCursor      

FETCH NEXT FROM TidCursor INTO @rec1_Tid, @rec1_PG, @rec1_Loc, @rec1_MainSubCon
.
.
.

DECLARE AttnCursor SCROLL CURSOR FOR 
    SELECT TimeIn, TimeOut, Location 
    FROM Attendance
    WHERE TID = @rec1_Tid 
      AND (Timein BETWEEN @SDate AND @EDate) 
      AND (Timeout BETWEEN @SDate AND @EDate) 
      AND (Timein IS NOT NULL AND timeout IS NOT NULL)  
    ORDER BY TimeIn

-- variables used to check for multiple logins in the same day
SET @curDate = '';
SET @preDate = '';

OPEN AttnCursor         

FETCH NEXT FROM AttnCursor INTO @indt, @outdt, @inloc   

WHILE (@@FETCH_STATUS = 0)
BEGIN
   .
   .
   .

   FETCH NEXT FROM AttnCursor INTO @indt, @outdt, @inloc
END    -- END WHILE (@@FETCH_STATUS = 0)

-- Closes the cursor
CLOSE AttnCursor; 
DEALLOCATE AttnCursor;

FETCH NEXT FROM TidCursor INTO @rec1_Tid, @rec1_PG, @rec1_Loc, @rec1_MainSubCon

END -- END WHILE (@@FETCH_STATUS = 0)

-- Closes the cursor
CLOSE TidCursor; 
DEALLOCATE TidCursor;

The reason is that the arguments you pass are probably dates without a time indication, and so they are midnight references. 原因是您传递的参数可能是没有时间指示的日期,因此它们是午夜引用。 Any date that has a time reference, like is the case with log times, will be considered later than the midnight reference. 具有时间参考的任何日期(例如日志时间)都将于午夜参考。

For example, the following is true: 例如,以下内容是正确的:

2016-08-05 07:41:33 > 2016-08-05

The solution is simple. 解决方案很简单。 Instead of 代替

between @SDate and @EDate

write

between @SDate and dateadd(d, 1, @EDate)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM