0

I'm trying to use the following statement to check if the order is late, but it causes syntax error. How can I write it ?

select (enddate > targetdate ) as late from orders
4
  • SELECT enddate, targetdate FROM orders WHERE enddate > targetdate ? Commented Dec 24, 2015 at 11:47
  • No, I want to return flag in order to the compression Commented Dec 24, 2015 at 11:50
  • No, I want to return flag in order to the compression Commented Dec 24, 2015 at 11:51
  • What are you going to do with this flag? If it's only for display purposes, it's OK. If you want to use this flag for filtering though, it would be faster to handle late entries separately. Commented Dec 24, 2015 at 11:53

2 Answers 2

4

It looks like you're searching something similar to case expression:

select 
    case 
        when enddate > targetdate then 1 
        else 0 
    end as late
from orders
Sign up to request clarification or add additional context in comments.

Comments

1

I guess you need case

select 
    case 
        when enddate > targetdate then 'enddate  is greater' 
        else 'targetdate is greater' 
    end as late
from orders

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.