code_junkie

How do I compare two datetime fields in SQL 2005?

Nov 12th, 2011
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. DECLARE @p_date DATETIME
  2. SET @p_date = CONVERT( DATETIME, '14 AUG 2008 10:45:30',?)
  3.  
  4. SELECT *
  5. FROM table1
  6. WHERE column_datetime = @p_date
  7.  
  8. @p_date=14 AUG 2008 10:45:30
  9. column_datetime=14 AUG 2008 10:45:30
  10.  
  11. DECLARE @end datetime
  12. SET @end = DATEADD(ss,1,@p_date)
  13.  
  14. WHERE column_datetime >= @p_date AND column_datetime < @end
Add Comment
Please, Sign In to add comment