Solved

Query to Run bi-monthly pulling transactions dated 1-14 and 15-EOM

Posted on 2006-07-13
2
303 Views
Last Modified: 2008-02-01
I have a dts package that is currently scheduled to execute every other Tuesday.  I pull in the data from the previous 2 weeks (ending sunday) using the following on my where statement:

(DATEDIFF(week, TranDate, GETDATE()) IN (1, 2))

I have now been requested to change this to run on the 1st and 15th of each month.  

The run on the 1st should pull data from the 15 to the end of the previous month.
The run on the 15th should pull data from the 1st to the 14th of the current month.

Can I use a CASE statement in my selection criteria to pull based upon the run date?  I'd like it to be a little more generic than hardcoding the 1st and 15th.  For instance, if it had to be ran on the 16th, I'd still like it to pull the data for the 1st  - 14th.  

Thanks!
0
Comment
Question by:Angela_Wilcox
[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 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 50 total points
ID: 17103628
what about this:

where TranDate >= case when datepart(day, getdate())<15
  then convert(datetime, convert(varchar(10), dateadd(month,-1,dateadd( day, 15 - datepart(day, getdate()), getdate())) ,120), 120)
  else convert(datetime, convert(varchar(10), dateadd( day, 1 - datepart(day, getdate()), getdate()) ,120), 120)
  end
and TranDate < case when datepart(day, getdate())<15
  then convert(datetime, convert(varchar(10), dateadd( day, 1 - datepart(day, getdate()), getdate()) ,120), 120)
  else convert(datetime, convert(varchar(10), dateadd( day, 15 - datepart(day, getdate()), getdate()) ,120), 120)
 end
                 
0
 

Author Comment

by:Angela_Wilcox
ID: 17107492
Thank you!  Looks like it should work!!
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
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 ?
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.

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