Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-07-13
2
Medium Priority
?
319 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 200 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
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
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

688 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