Click here to Skip to main content
16,011,905 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
Hi
Pl consider the following scenario, I am applying for leave from 01/03/2012 to 01/04/2012 (i.e from jan 1st to jan 4th 4 days) Now after applying leave i am again applying for leave on 01/02/2012 to 01/03/2012 (2nd jan to 3rd jan) now I should not allow to apply leave within this period as I have taken leave during this period
how to do it pl help
Posted

1 solution

Hope this helps


SQL
DECLARE @LeaveMaster AS  TABLE
(EmpId Bigint , StartUTC DateTime , EndUtc Datetime )
Declare @LeaveBegin AS Datetime
DEclare @LeaveEnd AS Datetime
DECLARE  @EmpId AS Bigint

SET @LeaveBegin ='01/02/2012'
SET @LeaveEnd ='01/03/2012'
SET @EmpId=1

INSERT INTO @LeaveMaster
SELECT 1,'01/02/2012' , '01/04/2012'


IF NOT EXISTS (SELECT * FROM @LeaveMaster L
WHERE
        (
               ( convert(varchar(50),@LeaveBegin,121)<= L.StartUTC   and convert(varchar(50),@LeaveEnd,121) > =L.EndUtc)
             or( convert(varchar(50),@LeaveBegin,121) between L.StartUTC and L.EndUtc)
             or( convert(varchar(50),@LeaveEnd,121)between L.StartUTC and L.EndUtc)
        ))
 INSERT INTO @LeaveMaster SELECT @EmpId,@LeaveBegin,@LeaveEnd


SELECT * FROM @LeaveMaster
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900