/*
This will return all address with a sales price.
*/
WITH ranked AS (
    SELECT
        av.id,
        av.humanReadableId as av,
        av.Alias as description,
       -- CONCAT(ad.HumanReadableId, ' - ',ad.Name) as customer ,
       ad.HumanReadableId as customer,
       ad.Name as customerDescription,
        ROW_NUMBER() OVER (
            PARTITION BY AddressId, sp.articleId
            ORDER BY ValidAfter DESC
        ) AS rn
    FROM [test1_AlplaPROD2.0_Read].[masterData].[SalesPrice] as sp (nolock) 

    /* av */
    left join
    [test1_AlplaPROD2.0_Read].[masterData].[Article] as av (nolock) on 
    av.id = sp.articleId

    /* address */
    left join
    [test1_AlplaPROD2.0_Read].[masterData].[Address] as ad (nolock) on 
    ad.id = AddressId

)
SELECT *
FROM ranked
WHERE rn = 1
and ranked.av = '[articleCheck]'

order by customerDescription