Click here to Skip to main content
15,911,030 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
IF (@user_leave_type = 3)
BEGIN
IF EXISTS( SELECT 1 FROM [dbo].[User_Leave] WHERE CONVERT(DATETIME,[start_date],101) BETWEEN CONVERT(DATETIME,@start_date,101) AND CONVERT(DATETIME,@end_date,101) AND
CONVERT(DATETIME,[end_date],101) BETWEEN CONVERT(DATETIME,@start_date,101) AND CONVERT(DATETIME,@end_date,101) AND [user_id] = @user_id)
BEGIN
select @leave_status=leave_status from user_leave where user_id=@user_id and CONVERT(DATETIME,[start_date],101)= CONVERT(DATETIME,@start_date,101) AND CONVERT(DATETIME,[end_date],101) = CONVERT(DATETIME,@end_date,101)
If(@leave_status=1)
begin
SET @active_rec_in = 0 -- Leave Active

print '@active_rec_in 3'
INSERT INTO User_Leave
(
[ref_cat_id],
[user_id],
[leave_hour],
[start_date],
[end_date],
[leave_desc],
[active_rec_in],
[user_leave_type],
[shift_during_leave],
[shift_after_leave],
[worked_days_in_shift],
[task_delegated_to]
)
VALUES
(
@ref_cat_id,
@user_id,
@leave_hour,
@start_date,
@end_date,
@leave_desc,
@active_rec_in,
@user_leave_type,
@shift_during_leave,
@shift_after_leave,
@worked_days_in_shift,
@task_delegated_to
)
end
Posted
Updated 22-Oct-13 18:50pm
v3
Comments
Member 10256268 22-Oct-13 4:46am    
date range work when leave_stauts=null
if user update user_leave_type to 1 if user again insert dates between range it is not inserting in to table.it showing already dates are present
Member 10256268 22-Oct-13 4:47am    
expted output after user cancel leave if he apply leave for sme date or other date the dates should insert into table.
Member 10256268 22-Oct-13 4:58am    
any one help me in this.
Member 10256268 22-Oct-13 4:59am    
now full code is uploaded.
Member 10256268 22-Oct-13 5:17am    
if user cancel leave and again if he eneter date for leave its not inserting into table how to solve this issue.

1 solution

SQL
IF (@user_leave_type = 3)
BEGIN
IF EXISTS( SELECT 1 FROM [dbo].[User_Leave] WHERE CONVERT(DATETIME,[start_date],101) BETWEEN CONVERT(DATETIME,@start_date,101) AND CONVERT(DATETIME,@end_date,101) AND
CONVERT(DATETIME,[end_date],101) BETWEEN CONVERT(DATETIME,@start_date,101) AND CONVERT(DATETIME,@end_date,101) AND [user_id] = @user_id)
BEGIN
select @leave_status=leave_status from user_leave where user_id=@user_id and CONVERT(DATETIME,[start_date],101)= CONVERT(DATETIME,@start_date,101) AND CONVERT(DATETIME,[end_date],101) = CONVERT(DATETIME,@end_date,101)
If(@leave_status=1)
begin
SET @active_rec_in = 0 -- Leave Active

print '@active_rec_in 3'
INSERT INTO User_Leave
(
[ref_cat_id],
[user_id],
[leave_hour],
[start_date],
[end_date],
[leave_desc],
[active_rec_in],
[user_leave_type],
[shift_during_leave],
[shift_after_leave],
[worked_days_in_shift],
[task_delegated_to]
)
SELECT
@ref_cat_id,
@user_id,
@leave_hour,
@start_date,
@end_date,
@leave_desc,
@active_rec_in,
@user_leave_type,
@shift_during_leave,
@shift_after_leave,
@worked_days_in_shift,
@task_delegated_to

end
else
SELECT @message=[ref_name] FROM [dbo].[Reference_Categories] WITH (NOLOCK) WHERE [ref_type] = 'MESSAGE' AND [ref_cat_code]=1024

end

ELSE
IF NOT EXISTS( SELECT 1 FROM [dbo].[User_Leave] WHERE CONVERT(DATETIME,[start_date],101) BETWEEN CONVERT(DATETIME,@start_date,101) AND CONVERT(DATETIME,@end_date,101) AND
CONVERT(DATETIME,[end_date],101) BETWEEN CONVERT(DATETIME,@start_date,101) AND CONVERT(DATETIME,@end_date,101) AND [user_id] = @user_id )

BEGIN
SET @active_rec_in = 0 -- Leave Active

print '@active_rec_in 3'
INSERT INTO User_Leave
(
[ref_cat_id],
[user_id],
[leave_hour],
[start_date],
[end_date],
[leave_desc],
[active_rec_in],
[user_leave_type],
[shift_during_leave],
[shift_after_leave],
[worked_days_in_shift],
[task_delegated_to]
)

SELECT
@ref_cat_id,
@user_id,
@leave_hour,
@start_date,
@end_date,
@leave_desc,
@active_rec_in,
@user_leave_type,
@shift_during_leave,
@shift_after_leave,
@worked_days_in_shift,
@task_delegated_to

END
ELSE

IF NOT EXISTS( SELECT 1 FROM [dbo].[User_Leave] WHERE CONVERT(DATETIME,[start_date],101) = CONVERT(DATETIME,@start_date,101) AND [user_id] = @user_id OR CONVERT(DATETIME,[end_date],101) = CONVERT(DATETIME,@end_date,101))
BEGIN
SET @active_rec_in = 0 -- Leave Active

--print '@active_rec_in 3'
INSERT INTO User_Leave
(
[ref_cat_id],
[user_id],
[leave_hour],
[start_date],
[end_date],
[leave_desc],
[active_rec_in],
[user_leave_type],
[shift_during_leave],
[shift_after_leave],
[worked_days_in_shift],
[task_delegated_to]
)
SELECT
@ref_cat_id,
@user_id,
@leave_hour,
@start_date,
@end_date,
@leave_desc,
@active_rec_in,
@user_leave_type,
@shift_during_leave,
@shift_after_leave,
@worked_days_in_shift,
@task_delegated_to

END
END
 
Share this answer
 
Comments
Member 10256268 22-Oct-13 4:55am    
what did u change in this code
same issue is coming.
Member 10256268 22-Oct-13 4:57am    
This is not working.

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