• another way of doing it without windowed function:

    SELECT pl.ID, usr.FirstName +' ' + usr.Surname as Createdby, pl.ProspectGuid, pl.MobileNumber as CTN, pl.Firstname + ' ' + pl.Surname CustomerName,

    Convert(varchar(10),pl.CallBackDate, 103) as CallBackDate, pl.CallBackTime as CallBackTime

    , lfd.PricePlan as Tariff

    , lfd.Price

    ,Convert(varchar(10),lfd.ContractEndDate) as ContractEndDate

    FROM ProspectLead pl

    inner join dbo.UserAccount USR (nolock) on USR.ShortAbbr = pl.CallBackSetBy

    cross apply (select top 1 l.PricePlan, l.Price, l.ContractEndDate from dbo.LeadFrontierData l where l.LeadID = pl.id

    order by l.PricePlan, l.Price, l.ContractEndDate) lfd

    where((@Responsibility = 14) or (pl.CallBackSetBy = @UserAbbr))

    and CallBackDate is not null

    and CallBackTime is not null

    and CallBackDate = @TodaysDate

    Just curious, is any particular reason why you're using NOLOCK?

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]