Solved

Previous week

Posted on 2013-05-17
4
251 Views
Last Modified: 2013-05-22
I have a process that run in Monday morning at 8am and I want to get "send_date" from a previous week. It is a datetime sample 2010-01-23 00:00:00.000 . What would the select statement be like?

select *from table where send_date is from previouse week.
0
Comment
Question by:VBdotnet2005
[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 16

Assisted Solution

by:Surendra Nath
Surendra Nath earned 125 total points
ID: 39175817
you want to get the the send_date column of previous_week's from a table? if so, please do the below

in the below scenario I am assuming two things

1) your table name is X_table
2) your datetime sample or what ever is stored in a column sample_dt

replace them as in your actual stuff.

select send_date from x_table
where abs(datediff(dd,sample_dt,getdate())) = 7

Open in new window

0
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 125 total points
ID: 39176046
SELECT ...
FROM dbo.tablename
WHERE
    send_date >= DATEADD(DAY, -7, DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 0)) AND
    send_date < DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 0)


You should avoid using any function, such as DATEDIFF(), on the column itself if at all possible, because if any function is used, SQL won't be able to fully utilize the index on that column.
0
 
LVL 12

Assisted Solution

by:sachitjain
sachitjain earned 125 total points
ID: 39178102
select * from table where Convert(varchar,send_date,106) = Convert(varchar,dateadd(day, -7, getdate()), 106)
0
 
LVL 41

Assisted Solution

by:Sharath
Sharath earned 125 total points
ID: 39178684
see this
SELECT * 
  FROM dbo.tablename 
 WHERE send_date >= DATEADD(day, -7, CONVERT(DATE, GETDATE())) 
   AND send_date < CONVERT(DATE, GETDATE()) 

Open in new window

0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

705 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