Solved

SQL Server query last seven days

Posted on 2013-12-06
4
666 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

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 …
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

623 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