?
Solved

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

Posted on 2011-09-23
3
Medium Priority
?
362 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Six Sigma Control Plans
Starting up a Project
Suggested Courses

800 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