0

Possible Duplicate:
SQL query to select dates between two dates

how to fetch record between two dates in sql server 2008. im using I-batis query

eg.

 select * from T_SETTLEMENT_TRANSACTION WHERE status='PEND' and from_date_time >='2013-01-09 04:16:52.0' AND to_date_time<='2013-01-09 04:16:52.0' 

where two columns are in datetime format in Sql server 2008

Community
  • 1
  • 1
Manu
  • 3,179
  • 23
  • 57
  • 69

1 Answers1

3

You could use SQL 2005's BETWEEN operator i.e.

WHERE createdate BETWEEN '01-01-01 21:20:32.71' AND '10-01-01 21:20:32.71'

Edit: If you want to fetch data between two different fields you should be able to do the following

WHERE createdate >= from_date AND createdate < to_date

Let me know how it works!

Bill
  • 31
  • 4
  • Thanks Bill. One more query.Suppose if im selecting from two columns.what i have to change.(say for From _date column and To_date column) – Manu Jan 10 '13 at 17:37
  • 1
    [Using between to check datetime values is perhaps not the best idea](http://stackoverflow.com/questions/14153837/datediff-or-between-for-date-ranges-in-sql-queries/14153977#comment19604719_14153977) – Mikael Eriksson Jan 10 '13 at 17:45