Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to build a query based on today's date... 20th 1

Status
Not open for further replies.

beetlebailey

Programmer
Jan 4, 2005
51
US
Hello I am trying to write a query based on today's date:

select partno as [Part Number]
from testers
group by partno, line, [day], [hour]
HAVING line=501 and [day]=20 and [hour]=6
order by line, [day], [hour]

In the HAVING statement I would like to have SQL put in today's date automatically. This query will be used on a daily basis. Is this possible? I have tried today(), now(), day(), datepart(dd,date) with no success. Thanks for any suggestions.
 
Tried GetDate() yet?



Catadmin - MCDBA, MCSA
"If a person is Microsoft Certified, does that mean that Microsoft pays the bills for the funny white jackets that tie in the back???
 
Not sure what field you want to compare todays date for as you havent specified, but have you tried getdate()
Code:
select partno as [Part Number]
from testers
group by partno, line, [day], [hour]
HAVING line=501 and [day]=datepart(dd, getdate()) and [hour]=6
order by line, [day], [hour]

"I'm living so far beyond my income that we may almost be said to be living apart
 
Oh, BTW, if you're looking specifically for part of the date (such as your notes about Day and Hour), lookup DatePart() and Day() in Books Online.



Catadmin - MCDBA, MCSA
"If a person is Microsoft Certified, does that mean that Microsoft pays the bills for the funny white jackets that tie in the back???
 
WOW, that works. Thanks so much for the replies and so promptly too.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top