Solved

SQL Server query last seven days

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

734 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