Předpokládám, že existují jiné způsoby, jak to udělat, ale myslím, že to funguje:
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)
Zde je SQLFiddle hrát.
EDIT:Vlastně je to asi moc složité. Zkuste toto:
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)