Solved

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

Posted on 2011-09-23
3
322 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This is an explanation of a simple data model to help parse a JSON feed
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now