Home Forums SQL Server 2008 T-SQL (SS2K8) Avoiding cursor: Help with getting only first match after previous match RE: Avoiding cursor: Help with getting only first match after previous match

  • I'll try to express it better - but I'm beginning to think its a procedural not a set-based problem.

    Take a row from #Table1

    Match the first row (Minimum Date) in #Table2 on the text field call this Match1.

    Take the next row from #table1

    Match the first row in #Table2 on text field where (minimum date that comes after Match1) - call this Match2 on text field

    Take Nth row from #Table1

    Match on text field where date = minimum date that comes after matchN

    All #Table1 rows should have a match.

    So the rule is when a #Table2 entry has now been matched THE MATCHED ROW AND ALL PRECEEDING ROWS on #Table2 should be excluded from future matches.