Home Forums SQL Server 2008 T-SQL (SS2K8) Iterating through records and ignoring unwanted rows RE: Iterating through records and ignoring unwanted rows

  • Hi,

    I'd use rownumber() to do that. Given what you've described then this should do the trick:

    SELECT

    x.TargetID, x.TargetName, x.Interaction, x.Created

    FROM

    (

    SELECT

    *, ROW_NUMBER() OVER (PARTITION BY TargetName, [Interaction] ORDER BY [Created]) AS Occurrance

    FROM #Visits

    ) AS x

    WHERE

    x.[Occurrance] = 1

    AND [x].[Interaction] = 'target_acquired'

    DROP TABLE #Visits



    MCSE: Data Platform
    MCSE: Business Intelligence
    Follow me on Twitter: @WazzTheBadger
    LinkedIn Profile: Simon Osborne