11

I want to write a sql query for the following excel-query. What should be the appropriate query?

IF

(
    (project. PA_SUBMIT_DATE )-(project. PA_AGREED_SUBMIT_DATE) 
    >=0;
    "YES";
    "NO"
)

i.e Date difference should be greater than or equal to zero. If so return yes else no.Please help me here.

Giannis Paraskevopoulos
  • 18,261
  • 1
  • 49
  • 69
TheNightsWatch
  • 371
  • 10
  • 26

2 Answers2

12

It would look something like this:

(case when project.PA_SUBMIT_DATE >= project.PA_AGREED_SUBMIT_DATE
      then 'YES' else 'NO'
 end)

Note: You can use >= for dates in both Excel and SQL and (I think) it makes the code easier to understand. The rest is just the standard SQL for a condition in a select.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
3

Looks like you want to return a "YES" if the PA_SUBMIT_DATE is greater than or equal to the PA_AGREED_SUBMIT_DATE:

SELECT CASE WHEN PA_SUBMIT_DATE >= PA_AGREED_SUBMIT_DATE 
          THEN 'YES' ELSE 'NO' 
       END AS [ColumnName]
FROM PROJECT
T McKeown
  • 12,971
  • 1
  • 25
  • 32