Return "YES" / "NO" based on date comparison in sql

I want to write a sql query for the next excel query. What should be the relevant request?

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

ie The date difference must be greater than or equal to zero. If yes, return yes no. Please help me here.

+5
source share
2 answers

It will 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 Excel and SQL and (I think) that makes the code more understandable. The rest is standard SQL for the condition in select .

+11
source

It looks like you want to return β€œYES” if PA_SUBMIT_DATE greater than or equal to PA_AGREED_SUBMIT_DATE :

 SELECT CASE WHEN PA_SUBMIT_DATE >= PA_AGREED_SUBMIT_DATE THEN 'YES' ELSE 'NO' END AS [ColumnName] FROM PROJECT 
+3
source

Source: https://habr.com/ru/post/1201152/


All Articles