Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Razzle00
Starting Member
35 Posts |
Posted - 2010-04-14 : 13:36:50
|
Hi, I have a transaction with the date of 04/08/2010 07:30:00 AM that I am trying to pull with a SQL statement using the BETWEEN clause that is created by my application from dates entered by an end-user. Could anyone explain to me why the result of this SQL statement pulls nothing.SELECT * FROM mytable WHERE id= '001' AND trdate BETWEEN '04/08/2010' AND '04/08/2010' ORDER BY company The only way I can get the transaction to pull in by using this statement with the date range changed to the 9th.SELECT * FROM mytable WHERE id= '001' AND trdate BETWEEN '04/08/2010' AND '04/09/2010' ORDER BY company If a end-user enters a range of 04/08/2010,04/08/2010 it should pull all transactions on the 8th. If an end-user enters 04/08/2010,04/09/2010 it should pull all the transaction that happened on the 8th & 9th. But this is not the case as you can see with my example above. Any suggestions how to handle this?Thanks,Razzle |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
Razzle00
Starting Member
35 Posts |
Posted - 2010-04-14 : 14:04:45
|
Thanks for the explanation tkizer. I believe DATEADD(dd, 1, '04/08/2008') is the code I was looking for. Can I now work the statement this way?SELECT * FROM mytable WHERE id= '001' AND trdate BETWEEN '04/08/2010' AND DATEADD(dd, 1, '04/08/2010') ORDER BY company |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
Razzle00
Starting Member
35 Posts |
Posted - 2010-04-14 : 14:18:30
|
| Ok thanks. Got it now.Razzle |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-04-15 : 08:39:54
|
| Also input your dates in YYYYMMDD format so that it works for all datesettingsMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|