DECLARE @leavecount INT
SELECT @leavecount = SUM(TBLLeave.NoofDays)
FROM TBLLeave INNER JOIN
TBLPersonalInformation ON TBLLeave.EmployeeID = TBLPersonalInformation.EmployeeID INNER JOIN
RefLeaveStatus ON TBLLeave.Status = RefLeaveStatus.LeaveStatusID INNER JOIN
TBLLeaveEarned ON TBLLeave.EmployeeID = TBLLeaveEarned.EmployeeID
WHERE (TBLLeave.EmployeeID = 'haha') AND (RefLeaveStatus.StatusName = 'Approved')
GROUP BY TBLPersonalInformation.Surname, TBLPersonalInformation.FirstName, TBLPersonalInformation.MiddleName, RefLeaveStatus.StatusName
if(@leavecount < TBLLeaveEarned.Sick)
BEGIN
INSERT INTO TBLLeave(EmployeeID, [Date], [Year], LeaveID, NoofDays, Remarks, [Status]) VALUES('haha', '1/2', '2015', '1', '1', 'paleave', '1')
SELECT 'INSERT'
END
else
begin
SELECT 'You reach the limit'
end
I got the error in IF statement
The multi-part identifier "TBLLeaveEarned.Sick" could not be bound.