Przypuszczam, że można to zrobić na inne sposoby, ale myślę, że to działa:
DECLARE
@OrganizationID varchar(40)
SET @OrganizationID = 'SMESM1HTOVEOVE'
SELECT
ro.ResourceID,
ro.OrganizationID,
max(ro.EffectiveDate)
FROM
ResourceOrganization ro
WHERE
ro.OrganizationID = @OrganizationID
GROUP BY
ro.ResourceID,
ro.OrganizationID
HAVING
max(ro.EffectiveDate) = (
SELECT
max(EffectiveDate)
FROM
ResourceOrganization
WHERE
ResourceID = ro.ResourceID)
Oto SQLFiddle do zabawy.
EDYCJA:Właściwie to prawdopodobnie zbyt skomplikowane. Wypróbuj ten:
DECLARE
@OrganizationID varchar(40)
SET @OrganizationID = 'SMESM1HTOVEOVE'
SELECT
ro.ResourceID,
ro.OrganizationID,
ro.EffectiveDate
FROM
ResourceOrganization ro
WHERE
ro.OrganizationID = @OrganizationID
AND ro.EffectiveDate = (
SELECT
max(EffectiveDate)
FROM
ResourceOrganization
WHERE
ResourceID = ro.ResourceID)