0

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;
2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by BitBlt
0

You are not explaining your problem clearly. I can see several problems with your stored procedure code, but until I know what you expect your result to be I can't really suggest anything.

I ran your stored proc, and it seemed to properly add unique leave dates for each employee I tested. Is this not correct?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.