Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
leave_type table application table sanction table leave details tabel

leavetypeid empid empid empid
leavetypename startdate leavetype totalleave
noofleaves enddate noofleaves leavetype
leavetype status usedleave
noofleaes remainingleave

allignment is not proper first row is the first table like leave_type table like rest of the table

in this leave managmnt project, once application is sent to the hod after approving the leave depending on the status request or reject all the leave information stored in the leave details table like remaing leave,used leave... used leave each time upgrade... please write the query for that.
Posted
Updated 1-Feb-15 15:48pm
v2

Hi,
Please try below trigger on your leave table (in which you are going to updated your Leave Status)

SQL
Create Trigger UpdateLeaveDetails on [Leave]
For update
as
Declare @empid int;
Declare @LeaveStatus int;

select @empid=i.Emp_ID from inserted i;	
select @LeaveStatus=i.LeaveStatus from inserted i;

if (@LeaveStatus == 1)  -- 1 for approve
		UPDATE LeaveDetails SET remaing_leave = remaing_leave-1 ,used_leave = used_leave-1 where empid = @empid
		
	-- No Need to update LeaveDetails information if leave are rejected  
GO 
 
Share this answer
 
v4
Comments
Sumit Jawale 4-Feb-15 0:32am    
Here you can take @LeaveStatus as varchar and you cna check if (@LeaveStatus == 'Approve')
Member 10711518 4-Feb-15 2:13am    
thank u.

without using the trigger.how to write the normal innerjoin or subquery for above table.
Sumit Jawale 4-Feb-15 7:00am    
Hi, What exactly you want to do ? What i understood from your comment is if hod approves leave, then you need to update the remaining record count.Correct ??

If you dont want to use trigger then you can write two update statments to update leave status and to update remaining leaves.
Hi,
You can use trigger to update two tables.
 
Share this answer
 
Comments
Member 10711518 3-Feb-15 21:30pm    
please help me query for that

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