|
-
Mar 14th, 2005, 09:48 AM
#1
Thread Starter
Addicted Member
SQL Date Help
Hey,
I'm creating a service program in Access 2003
I have two tables:
tbl_Appliance
ApplianceNo (Primary Key)
SerialNo
ApplianceType
ApplianceManufacturer
ApplianceModel
ApplianceDescription
tbl_NextService
Nxt_Service_ID (Primary Key)
Appliance_ID (Foreign Key)
Nxt_Service_Date
as you can see the tbl_Appliance stores all data about the appliance, the tbl_NextService table stores the next service date of that appliance.
What i need to do is find all the dates stored within the database that match the month of the Computers system date. is this possible using access?
e.g.
if i have the date 23/03/2005 within the tbl_NextService table, this date will be queried as the system date is the 14/03/2005 (Date is in the same month as the system date)
VB Code:
SELECT tbl_Appliance.*, tbl_NextService.Nxt_Service_Date
FROM tbl_Appliance INNER JOIN tbl_NextService ON tbl_Appliance.Appliance_No = tbl_NextService.Appliance_ID
how would i add a WHERE clause to the above SQL statement
Thanks
-
Mar 14th, 2005, 09:52 AM
#2
Re: SQL Date Help
Code:
SELECT tbl_Appliance.*, tbl_NextService.Nxt_Service_Date
FROM tbl_Appliance INNER JOIN tbl_NextService ON tbl_Appliance.Appliance_No = tbl_NextService.Appliance_ID
WHERE MONTH(tbl_NextService.Nxt_Service_Date) = MONTH(NOW)
AND YEAR(tbl_NextService.Nxt_Service_Date) = YEAR(NOW)
Think that will do it.....if you are using Access. Otherwise, if you are using SQL Server, replace NOW with GETDATE()
Tg
-
Mar 14th, 2005, 09:59 AM
#3
Thread Starter
Addicted Member
Re: SQL Date Help
Hey techgnome,
works great thanks
Cheers
-
Mar 14th, 2005, 10:12 AM
#4
Thread Starter
Addicted Member
Re: SQL Date Help
HEY again
thanks again for the SQL
whould it also be possible to have the SQL WHERE clause you gave me to work to find dates that are in that WEEK thanks
-
Mar 14th, 2005, 01:07 PM
#5
Re: SQL Date Help
Hmmm.....I've never tried that, but if there is a WEEK function, then it would be the same, except replace MONTH with WEEK.... But that's if it exists. IF it doesn't then you may need to look at the Format function and see if there is an option in there that returns the week number.
Tg
-
Mar 14th, 2005, 06:26 PM
#6
Thread Starter
Addicted Member
Re: SQL Date Help
Tired the WEEK function but seems not to exist..oh well....
I have another question for you.
How would i query the current system date to data in the tables
e.g
If the date today is the 15/03/2005 then all the dates 15/03/2005 in the table will be quiried...any idea how i would do tha?
i think i could use the Date() function but not sure how to set the SQL
Any help would be great
-
Mar 15th, 2005, 08:15 AM
#7
Thread Starter
Addicted Member
Re: SQL Date Help
Hey
i have a solution to finding dates that is between the system date and the next seven days anyway. (Technically a week...lol)
VB Code:
SELECT tbl_Appliance.*, tbl_NextService.Nxt_Service_Date
FROM tbl_Appliance INNER JOIN tbl_NextService ON tbl_Appliance.Appliance_No = tbl_NextService.Appliance_ID
WHERE (((tbl_NextService.Nxt_Service_Date) Between Date() And Date()+7));
The above SQL finds dates that are between the current date and the date in seven days time...
-
Mar 15th, 2005, 11:41 AM
#8
Re: SQL Date Help
Since you are only asking for the date and not the time then that will work fine. Another syntax is
the SomeDate >= SomeOtherDate And SomeDate < SomeEndDate + 1.
When you think about it, its not that complicated as some people make it out to be.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|