Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

SQL Server:differenza in giorni per due date in righe separate

Puoi fare un self join per farlo apparire su "una riga". In questo modo:

SELECT DateDiff(day,BASE.ReportCompleteDate, FORM.ReportCompleteDate) as Diff
FROM TABLE_NAME_YOU_DID_NOT_SAY BASE
LEFT JOIN TABLE_NAME_YOU_DID_NOT_SAY FORM ON BASE.ReportId = FORM.ReportID AND FORM.ReportType = 'Form Completed'
WHERE BASE.ReportType = 'PaperRecieved'