I tried using this query which will return the correct values when ran in sql manager:
Code: Select all
declare @value as decimal(18,5)
declare @payroll_start as date
declare @payroll_stop as date
set @payroll_stop = GetDate()
Set @value = (DatePart(dy, @payroll_stop) - (12.0 - DatePart(dw,1))) / 14.0
IF @value % 1 <> 0
Begin
set @payroll_start = @payroll_stop
While @value % 1 <> 0
Begin
Set @payroll_start = Dateadd(Day, -1, @payroll_start)
Set @value = (DatePart(dy, @payroll_start) - (12.0 - DatePart(dw,1))) / 14.0
End
set @payroll_start = DateAdd(Day, 1, @payroll_start)
End
Else
Begin
set @payroll_start = DateAdd(Day, -13, @payroll_stop)
End
Select @payroll_start as [Period Start], @payroll_stop as [Period Stop]
The problem I have is I always get an error "Incorrect syntax near the word 'declare' "
I have tried to read the documentation, but its lack of explanation makes it hard to figure this out.