moest plakken niet lukken

/****** Object: StoredProcedure [dbo].[ptsp_GetRequestsToApprove] Script Date: 18/01/2017 10:46:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[ptsp_GetRequestsToApprove]
@PtUserID INTEGER
AS
DECLARE @LanguageID integer
DECLARE @Customer integer
DECLARE @User_ID integer
DECLARE @DefaultLevel integer
DECLARE @Delegate integer
DECLARE @today integer
DECLARE @TimeNow INTEGER
DECLARE @Timezone_Requester INTEGER
DECLARE @AddOrSubstrackADay INTEGER

SET @TimeNow = (DATEPART(HH,GETDATE()) * 60 ) + DATEPART(MI,GETDATE())

set @today = CAST(CONVERT(CHAR,getDate(),112)AS INTEGER)
SET @AddOrSubstrackADay=0

SELECT @Timezone_Requester=C.TIMEZONEID FROM PT_USERS P,CUSTOMER C WHERE P.CUSTOMER=C.CUSTOMER AND PT_USERID=@PtUserID
EXEC ptsp_ConvertTimeToTimeZone NULL,@Timezone_Requester,@TimeNow,@AddOrSubstrackADay OUTPUT

IF @AddOrSubstrackADay <> 0 EXEC sp_AddToDate @AddOrSubstrackADay,@today OUTPUT

CREATE table #result(
RECNR int,
PERSNR int,
BOOKDATE int,
AUTHORISATION_LEVEL int,
ABSENCE_ID INT,
PAINTTIME INT,
PERSON_NAME varchar(100),
ABSENCE_CODE varchar(10),
DEPART_NAME varchar(50),
ABSENCE_NAME varchar(50),
COMMENT_TEXT text)

DECLARE USERS_CURSOR CURSOR FOR
select pt_userid from pt_users where pt_userid = @ptuserid or pt_userid in
(select pt_userid from outofoffice where delegate = @PtUserID and @today between datefrom and dateto)
OPEN USERS_CURSOR
FETCH NEXT FROM USERS_CURSOR INTO @Delegate
WHILE (@@FETCH_STATUS <> -1)
BEGIN
IF (@@FETCH_STATUS <> -2)
BEGIN
select @LanguageID = pp_users.languagenr, @User_ID = pt_users.user_id,@Customer=pp_users.customer
from pp_users, pt_users
where (pt_users.pt_userid = @Delegate) AND (pt_users.user_id = pp_users.user_id)

IF NOT @LanguageID=2 SET @LanguageID = 1

select @DefaultLevel = absreq_lvl
from FIXED_ROLE, pp_users
where pp_users.customer=@Customer
AND (pp_users.user_id = @User_ID)
AND (pp_users.FIXED_ROLE = FIXED_ROLE.FIXED_ROLE)

insert into #result exec ptsp_priv_RequestsForUser @delegate, @LanguageID, @Customer, @User_ID, @DefaultLevel
FETCH NEXT FROM USERS_CURSOR INTO @Delegate
END
END
CLOSE USERS_CURSOR
DEALLOCATE USERS_CURSOR
select * from #result where recnr in
(select distinct recnr from #result)
drop table #result