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

SQL For Getting Records in a Date Range 1

Status
Not open for further replies.

gall3on

Technical User
Mar 15, 2007
35
US
Hi,

I'm still feeling my way around SQL and need some assistance.

I have the following SQL below:
SELECT [All SOS with All CIDs].Date, [All SOS with All CIDs].SOS, sum([All SOS with All CIDs].Sumits) AS Submits INTO [Two Weeks]
FROM [All SOS with All CIDs]
WHERE ((([All SOS with All CIDs].Date) Between [Enter Start Date] And [Enter End Date]))
GROUP BY Date, SOS;

Basically, it helps me pull records within a certain date range.

How would I change this code if I want it to find records for the latest 14 days without having to put in dates? I just want it to return records from the latest 14 days.

 
Code:
SELECT A.[Date], A.SOS, SUM(A.Sumits) AS Submits INTO [Two Weeks]
FROM [All SOS with All CIDs] As A
WHERE A.[Date] Between DateAdd("d", -14, Date()) And Date()
GROUP BY [Date], SOS;
 
Wow, that was a pretty awesome solution. Thanks Golom!
 
Another way:
Code:
SELECT [Date], SOS, SUM(Sumits) AS Submits INTO [Two Weeks]
FROM [All SOS with All CIDs]
WHERE (Date()-[Date]) Between 0 And 14
GROUP BY [Date], SOS;

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top