Need to simplify [duplicate]

2019-09-21 11:59发布

This question is an exact duplicate of:

 WHERE (((tblNewCaseLog.CasePersonAddress) Like "*" & GetCriteria() & "*") AND ((DatePart("yyyy",    
  [DateLog])) Between DatePart("yyyy",Now())-1 And DatePart("yyyy",Now())))
  ORDER BY tblNewCaseLog.DateLog DESC;

--Really need to improve old Access syntax to SQL 2008 for migration. Gracias!

1条回答
萌系小妹纸
2楼-- · 2019-09-21 12:46
WHERE tblNewCaseLog.CasePersonAddress Like '%' + @GetCriteria + '%' 
     AND 
     YEAR([DateLog]) Between YEAR(GETDATE())-1 And YEAR(GETDATE())
ORDER BY tblNewCaseLog.DateLog DESC;

A better performance efficient solution would be

WHERE tblNewCaseLog.CasePersonAddress Like '%' + @GetCriteria + '%' 
     AND 
     [DateLog] >= DATEADD(YEAR, DATEDIFF(YEAR,0,GETDATE()) -1, 0) 
     AND 
     [DateLog] <= DATEADD(YEAR, DATEDIFF(YEAR,0,GETDATE()) + 1, -1)
ORDER BY tblNewCaseLog.DateLog DESC;
查看更多
登录 后发表回答