Solved

SQL Server query last seven days

Posted on 2013-12-06
4
659 Views
Last Modified: 2013-12-06
I need to query a SQL Server table to find records that have been entered within the last seven days.  I am new to SQL Server.  Thanks.

select column1, column2, column3
from mytable1
where ?
0
Comment
Question by:newtoperlpgm
4 Comments
 
LVL 17

Assisted Solution

by:dbaSQL
dbaSQL earned 166 total points
ID: 39701804
You're going to need a dateField of some sort in the table.  If you have that, I suppose you could do it one of two ways:

select column1, column2, column3
from mytable
where datefield >= dateadd(day,-7,getdate())

or

select column1, column2, column3
from mytable
where datefield between dateadd(day,-7,getdate()) and getdate()


Do you have a datefield in the table?
0
 
LVL 35

Accepted Solution

by:
YZlat earned 167 total points
ID: 39701808
select column1, column2, column3
from mytable1
where datefield > DATEADD(day, -7, GETDATE())
0
 
LVL 9

Assisted Solution

by:QuinnDex
QuinnDex earned 167 total points
ID: 39701811
where datecolumn > DATEADD (day , -7 , GETDATE() )

Open in new window

0
 

Author Comment

by:newtoperlpgm
ID: 39702273
perfect, thank you.
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sql join/ assign small # first 10 80
Filtered index 5 55
Optimizing a query 3 33
SQL Server merge records in one table 2 10
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now