Click here to Skip to main content
16,016,562 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The updation is not happening when the start date and end date have with in the existed date range

How can i do this logic.I have the below query can any one correct it to achieve correct process

SQL
ALTER PROCEDURE [dbo].[spUpdateLeaveAllocation]
 (@ID int,
  @EmpCode int,  
  @StartDate Varchar(50),
  @EndDate Varchar(30),
  @NumDays float,
  @Reason Varchar(Max),
  @LeaveMode Varchar(50),
  @ApplyDate Varchar(50),
  @ReturnValue int out)
 As
 BEGIN
 Declare @CompCode int;
 SET @CompCode=(SELECT CompCode FROM EmpMaster WHERE EmpCode=@EmpCode);

 IF( SELECT COUNT(*) FROM LeaveAllocation WHERE (EmpCode=@EmpCode) AND (StartDate Between (@StartDate) AND (@EndDate)
OR @StartDate Between (StartDate) AND (EndDate) 
OR @EndDate Between (StartDate) AND (EndDate)
OR EndDate Between (@StartDate) AND (@EndDate)))>0
BEGIN
SET @ReturnValue=-2
END
ELSE
 BEGIN
 UPDATE LeaveAllocation SET StartDate=@StartDate,EndDate=@EndDate,[No.ofDays]=@NumDays,Reason=@Reason,LeaveMode=@LeaveMode,AppliedDate=@ApplyDate Where ID=@ID
 SET @ReturnValue=2
 END
 END
Posted

1 solution

 AND (StartDate Between (@StartDate) AND (@EndDate)<br />
OR @StartDate Between (StartDate) AND (EndDate) <br />
OR @EndDate Between (StartDate) AND (EndDate)<br />
OR EndDate Between (@StartDate) AND (@EndDate)))>0


Given that the date formats are appropriate just the following two conditions should be sufficient to run the query.
The other two conditions don't make much sense.
(StartDate Between (@StartDate) AND (@EndDate) OR<br />
EndDate Between (@StartDate) AND (@EndDate))
 
Share this answer
 
Comments
kida atlantis 26-Nov-13 0:13am    
i have start date 5-11-2013 and End date is 7-11-2013 .if i update startdate to 6-11-2013 ,it will not update even though i dont have data..any idea? I changed the if condition as you said above

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