9

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
  • 17,836
  • 1
  • 48
  • 66
TheNightsWatch
  • 301
  • 7
  • 22

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,198,228
  • 53
  • 572
  • 709
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,786
  • 1
  • 24
  • 32