0

I have a query like this. And I want to know if there are substitutes for the date inline code condition?

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

Here is a sample query

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())  
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
cris gomez
  • 131
  • 1
  • 15

1 Answers1

1

where GETUTCDATE() between (p.PeriodBeginDate) AND DATEADD("dd",180, (p.PeriodEndDate))

DeepakJ
  • 378
  • 4
  • 14
  • is there a way to recode this DATEADD("dd",180, (p.PeriodEndDate))? – cris gomez Feb 24 '15 at 09:32
  • @crisgomez It won't cause a performance issue. The function itself does not cause a performance issue. The number of records that is being filtered by this condition may cause a decrease in performance, but then your problem is elsewhere, not in this condition if the condition is as per your required logic. – Radu Gheorghiu Feb 24 '15 at 09:37
  • Keeping data in the datetime format using DATEADD is most likely to be quicker.You can refer from http://stackoverflow.com/questions/2103687/how-does-dateadd-impact-the-performance-of-a-sql-query – DeepakJ Feb 24 '15 at 09:39