[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2011-09-23
3
Medium Priority
?
369 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
[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
3 Comments
 
LVL 7

Accepted Solution

by:
Jacobfw earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Starting up a Project
Suggested Courses

656 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