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

  • Actually #Table2 has the date, but as its only to the minute, there are duplicates - and the order of TEXT2 does not help - see the last few lines of the sample data - and my added column RowNum has duplicates. I think it originally comes from a text file somewhere, I could ask the programmer to re-import it for me, adding an identity column - trouble is he's run off his feet.

    But the 'best fit' solution devised by my cursor and replicated by Dwain's recursive cte is good enough for the end user.

    I had assumed (incorrectly as it turns out) that this problem would have a standard SQL solution as its a classic two file problem read file A, go down file B looking for a match. Save position in file B, read next from A, continue down file B from saved position. I've done this kind of thing in procedural languages many times.