Solved

Subtract two weeks from GETDATE.

Posted on 2007-03-26
2
1,427 Views
Last Modified: 2010-02-26
So I have the below query and I want to return a date but take it two weeks back so if the date taken is 3/26/2007 the date value used is 3/12/06. How may I accomplish this task?

select intBranchID, txtOrderSubType, sum(mnyActivityLaborPay + mnyLaborRevenue)
from tblSiebelComplete1000
where dteActualEndDate between SUBTRACT TWO WEEKS BACK (GETDATE)
group by intBranchID, txtOrderSubType
0
Comment
Question by:Levi Martin
2 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 250 total points
ID: 18794638
select intBranchID, txtOrderSubType, sum(mnyActivityLaborPay + mnyLaborRevenue)
from tblSiebelComplete1000
where dteActualEndDate between CAST(CONVERT(VARCHAR, GETDATE(),112) AS DATETIME)-14  AND GETDATE()
group by intBranchID, txtOrderSubType
 
0
 
LVL 4

Assisted Solution

by:opho
opho earned 250 total points
ID: 18794646
select
  intBranchID,
  txtOrderSubType,
  sum(mnyActivityLaborPay + mnyLaborRevenue)
from
  tblSiebelComplete1000
where
  dteActualEndDate between dateadd(week, -2, getdate()) and getdate()
group by
  intBranchID,
  txtOrderSubType

Like that?

--Steve
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SQL Server 2016 Developers Edition Install 4 59
SQL JOIN 6 39
Report Builder 9 31
Slow SQL query 12 29
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
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 combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

744 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

12 Experts available now in Live!

Get 1:1 Help Now