为什么这个查询不起作用?
SELECT ROW_NUMBER() OVER (
ORDER BY DocumentID
) peta_rn
, d.DocumentID
, d.IsReEfiled
, d.IGroupID
, d.ITypeID
, d.RecordingDateTime
, dbo.GetLatestStatusDateTime(d.DocumentID) AS LatestStatusDatetime
, dbo.FnCanChangeDocumentStatus(d.DocumentStatusID, d.DocumentID) AS CanChangeStatus
, d.IDate
, d.InstrumentID
, d.DocumentStatusID
, ig.Abbreviation AS IGroupAbbreviation
, u.Username
, j.JDAbbreviation
, inf.DocumentName
, it.Abbreviation AS ITypeAbbreviation
, d.DocumentDate
, ds.Abbreviation AS DocumentStatusAbbreviation
, dbo.GetFlatDocumentName(d.DocumentID) AS FlatDocumentName
FROM Documents d
INNER JOIN IGroupes ig
ON d.IGroupID = ig.IGroupID
LEFT JOIN ITypes it
ON d.ITypeID = it.ITypeID
LEFT JOIN Users u
ON u.UserID = d.UserID
LEFT JOIN DocumentStatuses ds
ON d.DocumentStatusID = ds.DocumentStatusID
LEFT JOIN InstrumentFiles inf
ON d.DocumentID = inf.DocumentID
INNER JOIN Jurisdictions j
ON j.JurisdictionID = d.JurisdictionID
WHERE 1 = 1
而这个有效:
SELECT ROW_NUMBER() OVER (
ORDER BY d.DocumentID
) peta_rn
, d.DocumentID
, d.IsReEfiled
, d.IGroupID
, d.ITypeID
, d.RecordingDateTime
, dbo.GetLatestStatusDateTime(d.DocumentID) AS LatestStatusDatetime
, dbo.FnCanChangeDocumentStatus(d.DocumentStatusID, d.DocumentID) AS CanChangeStatus
, d.IDate
, d.InstrumentID
, d.DocumentStatusID
, ig.Abbreviation AS IGroupAbbreviation
, u.Username
, j.JDAbbreviation
, inf.DocumentName
, it.Abbreviation AS ITypeAbbreviation
, d.DocumentDate
, ds.Abbreviation AS DocumentStatusAbbreviation
, dbo.GetFlatDocumentName(d.DocumentID) AS FlatDocumentName
FROM Documents d
INNER JOIN IGroupes ig
ON d.IGroupID = ig.IGroupID
LEFT JOIN ITypes it
ON d.ITypeID = it.ITypeID
LEFT JOIN Users u
ON u.UserID = d.UserID
LEFT JOIN DocumentStatuses ds
ON d.DocumentStatusID = ds.DocumentStatusID
LEFT JOIN InstrumentFiles inf
ON d.DocumentID = inf.DocumentID
INNER JOIN Jurisdictions j
ON j.JurisdictionID = d.JurisdictionID
WHERE 1 = 1
如您所见,唯一的区别是我指定了 d.DocumentID。无论如何我可以避免指定d.DocumentID
,而是只指定DocumentID
而不使用额外的选择?因为毕竟所有 documentID 都引用同一个值。