2

I have:
Table with columns A int, B int, C int

I need to build query like:

UPDATE
    Table
SET
    A -= B -- and then if A < 0 do A = C  

Is it possible to do without cursor? If it is useful, I use MS SQL Server 2008.

1 Answer 1

8

If I understood correctly this is what you're looking for

UPDATE
    Table
SET
    A = CASE 
           WHEN (A - B) < 0 THEN
             C
           ELSE 
               (A - B)
         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.