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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

query multiple tables using the current date

Status
Not open for further replies.

DanDarwood2004

Programmer
Sep 23, 2004
7
GB
I am trying to write a query that pulls information from a number of tables which are used as daily logs (with date as their primary key) for the current day. Not all of these tables are updated every day so I need a universal/system date to link them all together. I tired to use a query that returns the system date:

SELECT Now() AS SystemDate;

which works fine by itself but isn't allowed when used within another query as a linked table.

I can see having a date table within the database would solve this but I don't want to do this as it would require updating everyday and I'm sure there is a better and simpler solution.
 
Dan,

You you are selecting based on a date, you would want to do soemthing like
Code:
Select *
From MyTable
Where MyDateField = Date()
Now() includes TIME as well (Date Value like 38565.33225 which is 8/1/2005 7:58 AM here in Texas)



Skip,

[glasses] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal...
PULLEMALL![tongue]
 
The thing is that I am pulling quite a few tables together in the one query so would I not need a situation like:

SELECT ...
FROM MyTable1, MyTable2, MyTable3, MyTable4 ...
WHERE MyTable1.DateField = Date()
AND MyTable2.DateField = Date()
AND MyTable3.DateField = Date()
AND MyTable4.DateField = Date()
...

But this would also mean that if one of these tables had no record the query would return nothing ... maybe I just need to have a break and some coffee :)

I was thinking that if I linked the tables to a common date I would get around this.
 
Have a look at outer join.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 


Are these tables have an identical schema? If so do a series of UNIONS.

If not, how are they related?

Skip,

[glasses] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal...
PULLEMALL![tongue]
 
these tables aren't related to each other but as I they all have the date as a primary key I thought that I could link them in a query (if I had a global date table then they could all be linked to that I guess and all would be fine).

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top