Home Forums SQL Server 2008 T-SQL (SS2K8) How to get minimum date of an ID with respect to startdate? RE: How to get minimum date of an ID with respect to startdate?

  • Put a new line inside you code tags (which is a good idea in general, for readability)

    select a.*, (select max(Startdate)

    from @b-2 b

    where b.id=a.id and b.StartDate <=a.StartDate) StartDateB

    from @a a

    And be careful, that's likely going to be horrifically slow on anything more than a handful of rows

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass