Solved

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

Posted on 2006-07-13
2
302 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

749 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