sql server programming:
Ninel,
You can use the datepart function which returns the day of the week and
create a table similar to your example:
-- BEGIN SCRIPT
create table PayPeriod (StartPeriod datetime, EndPeriod datetime)
declare @date datetime
set @date = '01/01/2005' -- set the start date here
while @date <= '01/01/2020' -- set the end date here
begin
if datepart(dw,@date) = 2
begin
if not exists (select StartPeriod from PayPeriod where StartPeriod =
@date)
insert into PayPeriod (StartPeriod, EndPeriod)
values (@date, @date + 6)
end
set @date = @date + 1
end
select * from PayPeriod
After creating the table, you can even extend the date range to populate the
dates difference.
Let me know if it helps.
[quoted text, click to view] "ninel gorbunov via SQLMonster.com" wrote:
> The pay period at my company is from sunday to saturday.
> How can I calculate these pay periods for the next 5 years.
>
> Example:
>
> StartPeriod EndPeriod
> 20050612 20050618
> 20050619 20050625
> 20050626 20050702
>
> Thanks,
> Ninel
>
> --
> Message posted via
http://www.sqlmonster.com