0

In my code I have written an update query according to the date. That means, I have created an application for payroll, in that monthly they want to add month leave as two. If it is a new joinee that will separate two. This is the process I have done through my code. Now they want to change the model, that is, if the new joinee date of join has been greater than 15 days it should add one day leave. Please help me to do this. And this is my code befor I used:

UPDATE tbl_emploeedetails
SET    elbal = elbal - 2
WHERE  employeestatus = 'L'
       AND ( Month(doj) = Month(Getdate()) - 1
             AND Year(doj) = Year(Getdate())
             AND Day(doj) > 25 )
        OR ( Month(doj) = Month(Getdate())
             AND Year(doj) = Year(Getdate()) )

and this is month leave add query :

update tbl_emploeedetails 
    set elbal = elbal + 2 where employeestatus = 'L' 

1 Answer 1

1

You can use something like this

UPDATE YourTable
SET UpdateColumn =
(CASE
     WHEN <Condition1> THEN <Expression1> 
     WHEN <Condition2> THEN <Expression2> 
     ELSE <Expression3> 
END)

Example:

UPDATE YourTable
SET UpdateColumn =
(CASE
     WHEN A>B THEN D * 2
     WHEN A>C THEN D * 3
     ELSE D * 4
END)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.