Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 0.52 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. t-sql conditional date processing
  2. WHERE
  3.     (@argstart IS NULL AND @argend IS NULL)
  4. OR  (@argend IS NULL AND create_date > @Argstart)
  5. OR  (@argstart IS NULL AND create_date < @argend)
  6. OR  (Createdate BETWEEN @Argstart AND @Argend)
  7.        
  8. where (create_date >= @arg_start or @arg_start is null) and
  9.       (create_date <= @arg_end or @arg_end is null)
  10.        
  11. CREATE PROC usp_report
  12.     @StartDate datetime = '1900-01-01',
  13.     @EndDate datetime = '9999-12-31'
  14.  
  15. AS
  16.  
  17. SELECT *
  18. FROM MyTable
  19. WHERE DateField BETWEEN @Startdate AND @EndDate