Solved

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

Posted on 2006-07-13
2
293 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
2 Comments
 
LVL 142

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
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…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

911 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

26 Experts available now in Live!

Get 1:1 Help Now