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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Getdate()

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-04-22 : 21:49:46
Gary writes "I am still having trouble understanding the getdate function, and the SQL books I have don't offer that much information.

I am tapping into a database and want to do a query based on todays date. The query gives me the results I need but takes time in accomplishing the task. I am certian that if I correct my date area of the query it will save time. Here is the query:

SELECT convert(Char(10),flight.FlightDate,101) as Depart_Date,
flight.FlightNum, flight.GateDpt,
Flight_Delay.Delay_Code,
Flight_Delay.Minutes
FROM flight INNER JOIN Flight_Delay ON flight.id = Flight_Delay.flight_id
WHERE (((flight.Airline)="AA")
AND ((flight.DptCtyAct)="DFW"))
AND ((datepart(yy,flight.FlightDate) = datepart(yy, getdate())))
AND ((datepart(mm,flight.FlightDate) = datepart(mm, getdate())))
AND ((datepart(dd,flight.FlightDate) = datepart(dd, getdate())))
AND ((flight.FlightNum)<"3000")
AND ((flight_Delay.minutes)>"5")
AND ((flight_Delay.Delay_Code)<>"LT")

Here are the results:

Depart_Date FlightNum GateDpt Delay_Code Minutes 
----------- --------- ------- ---------- -------
04/18/2001 1140 A17 75B 33
04/18/2001 306 C20 99Z 23
04/18/2001 1750 C39 29A 23
04/18/2001 828 C29 46 15
04/18/2001 568 C17 99Z 9


It takes the server 01:55 to produce the results. How can I simplify the date function to just say (flight.flightDate = getdate(). I've tried but haven't had any luck.

Thanks.

Gary Costigan
Dallas, Tx.
"
   

- Advertisement -