[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Subtract two weeks from GETDATE.

Posted on 2007-03-26
2
Medium Priority
?
1,438 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
[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 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 1000 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 1000 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
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, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

649 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