Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL to get records between start of last week and end of last week

Posted on 2013-12-11
4
Medium Priority
?
10,841 Views
Last Modified: 2013-12-11
Hi chaps

Can someone help me with some SQL please? I need to select records with a "enter_date" field which is between the start of last week and the end of last week.

That is, not within the last 7 days, but within the last week period.

Any one know how to format that select section to do that?

Olly
0
Comment
Question by:stonneway
[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
  • 2
4 Comments
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 39711973
select * from yourtable
where enter_date >=  dateadd(wk, datediff(wk, 0, getdate()) - 1, 0)  --first day of last week
and enter_date <t dateadd(wk, datediff(wk, 0, getdate()), 0) --first day of this week
0
 
LVL 32

Accepted Solution

by:
Ephraim Wangoya earned 2000 total points
ID: 39711983
get rid of type

select * 
from yourtable
where enter_date >=  dateadd(wk, datediff(wk, 0, getdate()) - 1, 0)  --first day of last week
and enter_date < dateadd(wk, datediff(wk, 0, getdate()), 0) --first day of this week

Open in new window

0
 
LVL 19

Expert Comment

by:jss1199
ID: 39712021
WHERE
Datepart(Week,enter_date)=Datepart(week,current_timestamp)-1

Adding the above where statement will get all data with enter_date in the last full week.
0
 
LVL 1

Author Closing Comment

by:stonneway
ID: 39712169
Thanks for that
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

660 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