1

How to write a SQL query where I have a table called ACC_REQUEST?

There is a column in the table called REQUEST_STATUS with the values of 'pending', 'withdrawn', and 'completed

If the request status value = 'pending then select approver_name from ACC_APPROVAL, else select request status

2 Answers 2

1

You can use CASE

Like:

CASE x WHEN bah THEN FOO END CASE

http://dev.mysql.com/doc/refman/5.0/en/case.html

Sign up to request clarification or add additional context in comments.

Comments

1

Something like

SELECT 
    CASE
        WHEN ACC_REQUEST.REQUEST_STATUS = 'pending' THEN ACC_APPROVAL.APPROVER_NAME
        ELSE ACC_REQUEST.REQUEST_STATUS
    END as [put the name you wish for output column here, no square brackets]
FROM ACC_REQUEST
INNER JOIN ACC_APPROVAL ON [I'm assuming some kind of join condition here]

1 Comment

better answer then mine ;)

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.