Solved

SQL Server query last seven days

Posted on 2013-12-06
4
661 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

In this article I will describe the Backup & Restore 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.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
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 …

856 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