I am using SQL Server 2012 and working an a report currently that is asking me to find the difference in days between two dates.
Basically, for a particular ReportID, I'm trying to find the difference in days between the (ReportCompletedDate when the ReportType = 'PaperReceived') - (ReportCompletedDate when the ReportType = 'Form Completed')
I tried to give some records below...
ReportID ReportType ReportCompletedDate
450 PaperReceived 9/5/2013
450 Form Completed 8/13/2013
451 PaperReceived 9/7/2013
451 Form Completed 7/12/2013
452 PaperReceived 10/6/2013
452 Form Completed 3/13/2013
You can do a self join to make it appear on "one line". Like this:
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'