Rows

  • Hi,

    anybody got anyideas about how to pull only even rows from a table into a dynamic cursor ?

  • Define 'even rows'

    Do you have an identity column and only want rows where the id is 2,4,6,... ?

    Do you want every other row as defined by a certain order by?

    Off the point of the question, why do you need a cursor, let alone a dynamic one?

    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
  • You could use a query with Row_Number like:

    SELECT  a
    FROM    ( SELECT    ROW_NUMBER() OVER ( ORDER BY a ) AS RowNr
                      , a
              FROM      @evenRows
            ) AS x
    WHERE   x.RowNr % 2 = 0
    

    Assuming in the above that you want to order on a, and then get every second row.

    If you describe your problem in more detail we may be able to help better

    Andras


    Andras Belokosztolszki, MCPD, PhD
    GoldenGate Software

  • Hi

    Thanks for the replies. It was just somthing i had been playing around with. Yes i was thinking even rows in terms of 2,4,6,8 etc.

  • Even, in terms of what? Row position based on a certain order, an identity column, something else ????

    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

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply