您好,感谢您的阅读。我似乎在查询中从字段中提取日期时遇到问题。 Query中的所有其他字段都正确拉动,并且不会引发错误。但是,所有Document.ServiceDTTM列都显示NULL。 Document表中没有NULL值,所以我不确定为什么会显示它。我在某处使用了错误的JOIN类型吗?
DECLARE @StartDate datetime
DECLARE @EndDate datetime
SET @StartDate = '2015-08-01'
SET @EndDate = '2015-09-01'
USE Works
SELECT Patient_Iorg.organizationMRN AS MRN, IDX_User.AUsername AS TWUser, Document.ServiceDTTM, DocumentEvent.eventDTTM, Document_Type_de.EntryName AS NoteName FROM Document (nolock)
JOIN DocumentEvent ON Document.documentid = DocumentEvent.documentid
JOIN Document_Type_de ON Document.documenttypede = Document_Type_de.ID
JOIN IDX_User ON DocumentEvent.userid = IDX_User.ID
JOIN Person ON Document.PatientID = Person.ID
LEFT JOIN Patient_Iorg ON Person.id = Patient_Iorg.PersonID and Patient_Iorg.InternalOrganization = 3
WHERE
DocumentEvent.documenteventde IN (18)
AND
DocumentEvent.eventDTTM >= @StartDate
AND
DocumentEvent.eventDTTM <= @EndDate
AND
Document.Status LIKE 'Final%'
AND
Document.DocumentTypeDE IN (158)
ORDER BY
eventDTTM
以下信息:
XXXXXX adoctor NULL 8/1/2015 Note
XXXXXX adoctor NULL 8/1/2015 Note
XXXXXX aprovider NULL 8/1/2015 Note
XXXXXX aprovider NULL 8/1/2015 Note
XXXXXX aprovider NULL 8/1/2015 Note
XXXXXX aprovider NULL 8/1/2015 Note
XXXXXX aprovider NULL 8/1/2015 Note
XXXXXX aprovider NULL 8/1/2015 Note
XXXXXX aprovider NULL 8/1/2015 Note