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 |
azamsharp
Posting Yak Master
201 Posts |
Posted - 2006-10-06 : 11:01:46
|
Hi, I want to select a result only if today's date lies between the startdate and endDate. Like: SELECT StartDate, EndDate FROM Dates WHERE GETDATE() BETWEEN StartDate AND EndDate The above query does not work. Mohammad Azam www.azamsharp.net |
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2006-10-06 : 11:21:22
|
The query should work if the datatypes of the columns StartDate and EndDate are in fact DateTime.Try This:CREATE TABLE #Dates( StartDate DATETIME, EndDate DATETIME)INSERT INTO #DatesSELECT '2006-01-01', '2007-01-01'UNION ALLSELECT '2007-01-01', '2008-01-01'UNION ALLSELECT '2006-10-06', '2006-10-07'UNION ALLSELECT '2005-01-01', '2006-01-01'SELECT StartDate, EndDateFROM #DatesWHERE GETDATE() BETWEEN StartDate AND EndDateWhat are the datatypes of the 2 columns?Either that or your machine date is wrong.Duane. |
 |
|
azamsharp
Posting Yak Master
201 Posts |
Posted - 2006-10-06 : 11:26:03
|
Got it! Thanks :)Mohammad Azam www.azamsharp.net |
 |
|
|
|
|