flags for Alternate Rows

  • hey Guys,

    How can i set flag 1 and 0 for alternate rows using sql query?

    your help is appreciated...

    Id......Code....................Language.......Description................Flag

    ------------------------------------------------------------------------

    1.......Heating Cables......... German.......Heizbänder/Heizkabel.....1

    ......................................Russian.......??????? ??????..............1

    ......................................English........Heating Cables..............1

    2.......Heating Panels......... German.......Heizbänder/Heizkabel......0

    ......................................Russian.......??????? ??????...............0

    ..................................... English........Heating Cables...............0

    3.......Trnsformers............. German.......Heizbänder/Heizkabel.......1

    ..................................... Russian.......??????? ??????................1

    ......................................English........Heating Cables................1

    4.......TT3000.................. German........Heizbänder/Heizkabel........0

    ..................................... Russian........??????? ??????................0

    ..................................... English.........Heating Cables...............0

    i Hope this gives u clear idea about my requirement...

  • Try something like this

    SELECT * , ROW_NUMBER() OVER (ORDER BY ID) % 2 AS AlternatingFlag

    FROM SomeTable

    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
  • Hey Guys...

    i got it....

    Thanks

  • If you didn't use Gail's solution, would you mind posting your solution, please?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

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

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