このクエリが機能しないのはなぜですか?
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を指定することです。とにかく、指定する必要がなく、代わりに追加のSelectを使用せずd.DocumentID
にのみ指定することができますか?DocumentID
結局のところ、すべてのdocumentIDは同じ値を参照しているからです。