• Based on the very vague details provided this is the in-line table valued function I would use:

    CREATE FUNCTION dbo.ClientProductPrice (

    @ClientNo INT,

    @ItemCode INT,

    @InvoiceDate DATETIME -- in SQL Server 2008 and later can be DATE

    )

    RETURNS TABLE

    AS

    RETURN(

    WITH PriceRec AS (

    SELECT

    rn = ROW_NUMBER() OVER (ORDER BY PriceChangedDate DESC),

    NewPrice

    FROM

    MyTable

    WHERE

    ClientNo = @ClientNo AND

    ItemCode = @ItemCode AND

    PriceChangedDate <= @InvoiceDate

    )

    SELECT NewPrice FROM PriceRec WHERE rn = 1

    );

    No promises that this will work as I didn't create a table to do any testing.