all groups > sql server programming > june 2005 >
You're in the

sql server programming

group:

Calculating Pay Periods


RE: Calculating Pay Periods Edgardo Valdez, MCSD, MCDBA
6/17/2005 4:07:02 PM
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]
Re: Calculating Pay Periods Aaron Bertrand [SQL Server MVP]
6/17/2005 5:24:13 PM
How about a calendar table?
http://www.aspfaq.com/2519





"ninel gorbunov via SQLMonster.com" <forum@nospam.SQLMonster.com> wrote in
message news:4FFFC068F5F60@SQLMonster.com...
[quoted text, click to view]

Calculating Pay Periods ninel gorbunov via SQLMonster.com
6/17/2005 9:16:29 PM
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

--
AddThis Social Bookmark Button