SQL Server中的日期内联代码条件替换

时间:2015-02-24 09:20:13

标签: sql sql-server

我有这样的查询。我想知道日期内联代码条件是否有替代品?

(p.PeriodBeginDate) <= (GETUTCDATE())    
AND DATEADD("dd",180, (p.PeriodEndDate)) >= (GETUTCDATE())  

以下是示例查询

SELECT 
   r.ReviewRoleID, rpp.*    
FROM 
   dbo.rev_Period_Person AS rpp 
JOIN 
   dbo.rev_Period p ON rpp.PeriodID = p.PeriodID    
LEFT JOIN 
   dbo.rev_Review r ON rpp.PeriodID = r.PeriodID    
                    AND rpp.PersonID = r.RevieweePersonID    
                    AND r.ReviewRoleID = 2    
                    AND r.ReviewSelfAssessmentStatusID = 3    
                    AND r.IsActive = 1    
WHERE
    (p.PeriodBeginDate) <= (GETUTCDATE())    
    AND DATEADD("dd",180, (p.PeriodEndDate)) >= (GETUTCDATE())  

1 个答案:

答案 0 :(得分:1)

其中GETUTCDATE()在(p.PeriodBeginDate)和DATEADD之间(&#34; dd&#34;,180,(p.PeriodEndDate))