[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 371
  • Last Modified:

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

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
Bakersville
Asked:
Bakersville
1 Solution
 
JacobfwCommented:
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
 
TommySzalapskiCommented:
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
 
BakersvilleAuthor Commented:
Thank you for your response.  Worked a treat..
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now