• SQL_Surfer (8/12/2013)


    19table has following fields and data as follows

    ClientNo ItemCode NewPrice PriceChangedDate

    11234 205.00 8/1/2013

    11234 200 7/30/2013

    11234 195 7/2/2013

    11234 190 6/30/2013

    Whenever there is price changes, it records new price in this table.

    I need to return the NewPrice for the given clientNo, ItemCode and InvoicedDate.

    For e.g for InvocedDate of 7/1/2013, there may not be any records in the table with the PriceChanedDate.

    However, it should retrun NewPrice of 190 as Price from 6/30 to 7/1 remained 190. So it should return 190

    Any idea best way to write a function for this?

    Pretty sparse on details. You have been around here long enough to know we need more details than this.

    Maybe it is as simple order by PriceChangedDate? Hard to know what you are looking for.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/