Sqlserver
 sql >> Base de Dados >  >> RDS >> Sqlserver

DateDiff de 2 datas na mesma coluna SQL


Basta juntar a tabela a ela mesma:
SELECT t1.OrderNo,DATEDIFF(day,t1.LoadedStartDate,t2.LoadedStartDate)
FROM UnnamedTableFromQuestion t1
       INNER JOIN
     UnnamedTableFromQuestion t2
       on
         t1.OrderNo = t2.OrderNo
WHERE t1.OpNo = 1 and
      t2.OpNo = 4