Guyz i need changes in this stored procedure "between" or anything
like ven i enter a start date and end date on as 26 dec twice i get error
set @Result = (select COUNT(*) from Employee_Leave where Employee_Id = @Employee_Id and Leave_Date = @start_Date AND )
and does not duplicate the row`s
what i neeed is that when the user enters from 24 to 28 dec .. it should save al these ..
Now am not able to store after 26 ...(27,28)
how shuld i structure my query ... hope u guyz getting it !
StoredProcedure [dbo].[AddLeaveForm]
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[AddLeaveForm]
@Employee_Id numeric(18,0),
@Leave_Status varchar(50),
@Created_By numeric(18,0) ,
@Is_Active bit = 1 ,
@Modified_By numeric(18,0) = NULL,
@Modified_Date datetime = NULL,
@start_Date datetime,
@end_Date datetime
AS
BEGIN
BEGIN
while(@start_Date <= @end_Date)
BEGIN
declare @Result numeric(18,0)
set @Result = (select COUNT(*) from Employee_Leave where Employee_Id = @Employee_Id and Leave_Date BETWEEN @start_Date AND @end_Date)
if(@Result = 0)
begin
INSERT INTO
[Employee_Leave]
(
[Employee_Id] ,
[Leave_Date]
,[Leave_Status]
,[Created_By]
,[Created_Date]
)
VALUES
(
@Employee_Id ,
@start_Date
,@Leave_Status
,@Created_By
,CURRENT_TIMESTAMP
)
end
else
begin
select -1
end
set @start_Date = DATEADD(DD, 1, @start_Date);
END -- End While Loop
END
END
select * from Employee_Leave;