Help with SQL query

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bruno Panetta

    Help with SQL query

    Hi, I have a table like the following fields:

    TradeDate Item Price

    Now, suppose I want to do an update like this: every price
    corresponding to a date higher than '30 Sep 2005' will be reset to the
    latest price in that item. Can I do something like the following

    UPDATE Table t SET Price = (SELECT TOP 1 Price FROM Table q WHERE
    q.Item = t.Item ORDER BY TradeDate DESC) WHERE t.TradeDate > '30 Sep
    2005'

    or is there a better way?

    Thank you very much.

    Bruno

  • Jens

    #2
    Re: Help with SQL query

    Hi Bruno,

    Perfect :-D Looks good to me.

    HTH, Jens Suessmeyer

    Comment

    Working...