Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
kshitizgp
Starting Member
31 Posts |
Posted - 2011-12-30 : 11:07:37
|
Guyz i need changes in this stored procedure "between" like ven i enter a start date and end date on as 26 dec twice i get errorset @Result = (select COUNT(*) from Employee_Leave where Employee_Id = @Employee_Id and Leave_Date = @start_Date AND ) and does not duplicate the row`swhat 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 ONGOSET QUOTED_IDENTIFIER ONGOALTER 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 ASBEGINBEGIN 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; |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-01 : 02:17:20
|
i think you need only thisALTER 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 datetimeASINSERT INTO [Employee_Leave]([Employee_Id] ,[Leave_Date],[Leave_Status],[Created_By],[Created_Date])SELECT @Employee_Id , [Date],@Leave_Status,@Created_By,CURRENT_TIMESTAMPFROM dbo.CalendarTable(@start_Date, @end_Date,0,0) the code for CalendarTable you can find herehttp://visakhm.blogspot.com/2010/02/generating-calendar-table.html------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|