Solved

SQL Server query last seven days

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 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

24 Experts available now in Live!

Get 1:1 Help Now