Monday, March 19, 2012

Need script to add days to a date, and polulate another table

Hi guys n gals,
I'll confess now that I only know enough sql to get me by when web
developing, so I really need a hand with this one...
I've basically setup a Scheduling system within our office where people
chuck in projects and they get scheduled...
Having been asked to setup some recurring functionality, I've created
the site and the fields in a seperate table.
What I capture is the 'StartDay' and 'EndDay' (assuming a wly
recurring job) and all the other details so it can be populated into
the live system.
What I'm trying to acheive is to find next Mondays date (which I've got
from this: SELECT DATEADD(wk, DATEDIFF(wk, 6, getdate()), 6) think
it actually gets Sunday ) , then read the recurring table, pull
out the startday and endday, add them to next Mondays date and popluate
the live table fields StartDate and EndDate (as well as all the other
fields)
Hope this makes sense and I hope you kids can help me as I'm really
struggling
Thanks in advance
AdamAdam
You can use DATEPART(dw ...) to figure out what day of the w a date is
and math will take you to the next certain day of the w that you want.
You can use sp_helplanguage to figure out which day of the w is day 1 for
you, should that be necessary.
And so forth.
RLF
"tsgadam" <adamc@.databasegroup.co.uk> wrote in message
news:1138807651.032044.111320@.g14g2000cwa.googlegroups.com...
> Hi guys n gals,
> I'll confess now that I only know enough sql to get me by when web
> developing, so I really need a hand with this one...
> I've basically setup a Scheduling system within our office where people
> chuck in projects and they get scheduled...
> Having been asked to setup some recurring functionality, I've created
> the site and the fields in a seperate table.
> What I capture is the 'StartDay' and 'EndDay' (assuming a wly
> recurring job) and all the other details so it can be populated into
> the live system.
>
> What I'm trying to acheive is to find next Mondays date (which I've got
> from this: SELECT DATEADD(wk, DATEDIFF(wk, 6, getdate()), 6) think
> it actually gets Sunday ) , then read the recurring table, pull
> out the startday and endday, add them to next Mondays date and popluate
> the live table fields StartDate and EndDate (as well as all the other
> fields)
>
> Hope this makes sense and I hope you kids can help me as I'm really
> struggling
> Thanks in advance
> Adam
>|||Why should I consider using an auxiliary calendar table?
http://www.aspfaq.com/show.asp?id=2519
A bit a reading, a bit of work to set up.
But once you do, these types of queries will be easy.
"tsgadam" <adamc@.databasegroup.co.uk> wrote in message
news:1138807651.032044.111320@.g14g2000cwa.googlegroups.com...
> Hi guys n gals,
> I'll confess now that I only know enough sql to get me by when web
> developing, so I really need a hand with this one...
> I've basically setup a Scheduling system within our office where people
> chuck in projects and they get scheduled...
> Having been asked to setup some recurring functionality, I've created
> the site and the fields in a seperate table.
> What I capture is the 'StartDay' and 'EndDay' (assuming a wly
> recurring job) and all the other details so it can be populated into
> the live system.
>
> What I'm trying to acheive is to find next Mondays date (which I've got
> from this: SELECT DATEADD(wk, DATEDIFF(wk, 6, getdate()), 6) think
> it actually gets Sunday ) , then read the recurring table, pull
> out the startday and endday, add them to next Mondays date and popluate
> the live table fields StartDate and EndDate (as well as all the other
> fields)
>
> Hope this makes sense and I hope you kids can help me as I'm really
> struggling
> Thanks in advance
> Adam
>

No comments:

Post a Comment