Solved

Work out every 8 weeks from a start date in Microsoft sql 2005

Posted on 2011-09-23
3
352 Views
Last Modified: 2012-05-12
Hi everyone.

Can any please help me. I hope i explain this right

I have a sql table, with name addresses, emails etc, but have 2 extra, DateStarted, WeekPeriod

Now, i want to send an email every day, to these people, but, if WeekPeriod = 8 then i only send the email once in every 8 weeks, same as it was 4, then i send the email every 4 weeks from DateStarted.

Normall, i would write a command for each week and just allow x amount of entries, but this needs to be fully dynamic.

Can anyone understand what i mean and able to help.

Thank you
Baker


0
Comment
Question by:Bakersville
3 Comments
 
LVL 7

Accepted Solution

by:
Jacobfw earned 500 total points
ID: 36586487
Something like:

find the days between current date and date started
divide by seven to find weeks
divide by weekperiod
sutract the same (but rounded)
if not equal zero, it is not the correct week

where trunc(days_between(DateStarted,sysdate)/7,0)/WeekPeriod - trunc((trunc(days_between(DateStarted,sysdate)/7,0)/WeekPeriod),0) = 0

0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 36586489
The datediff function can be done by weeks
SELECT *
FROM table
WHERE DATEDIFF(ww,DateStarted,GETDATE()) = WeekPeriod

And you would run the query once per week.

If you wanted to run it once per day, then you would want
SELECT *
FROM table
WHERE DATEDIFF(day,DateStarted,GETDATE()) = 7*WeekPeriod
0
 
LVL 1

Author Closing Comment

by:Bakersville
ID: 36600703
Thank you for your response.  Worked a treat..
0

Featured Post

Independent Software Vendors: 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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

679 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