---
# System prepended metadata

title: Untitled

---

ORDER BY
  CASE
    WHEN (ClosingDate < GetDate())
    THEN 1
    ELSE 0
  END ASC,
  KEY_TBL.Rank DESC
  
  select name, (SELECT CASE WHEN
DATEPART(MONTH, '2016-10-28') > DATEPART(MONTH, '2016-09-29')  
THEN DATEDIFF(MONTH, '2015-08-28',  '2016-09-29') -1
ELSE (0) END) as NumberOfMonths from demo



SELECT CASE WHEN fecha_ini < CURRENT_DATE()
THEN (datediff(fecha_ini, FORMAT(CURRENT_DATE(), 'dd/MM/yyyy')))
ELSE ('Ayer')
END as 'date_diff'
FROM docs