How can i show in Table evry third record (row)

  • need help

    How can i  show in Table evry third OR fourth record (row)

    in my table i have 5600 Records

    and i wont to do like this

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

    1. aaaaaaaaaaaa
    2. bbbbbbbbbbbbb
    3. ccccccccccccccc
    4. ddddddddddddddddd
    5. aaaaaaaaaaaaaa
    6. bbbbbbbbbbbbbbbbb
    7. cccccccccccccccccc
    8. ddddddddddddddddd
    9. aaaaaaaaaaaa
    10. bbbbbbbbbbbbbb
    11. cccccccccccccc
    12. ddddddddddddddddd

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

    1   i wont to show only the RED (aaaaaaaaaaaaa)

    and insert the  RED new table

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

    2   i wont to insert the green (bbbbbbbbbbb)

    in a new table

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

    and the C also

    and the D also

    thnks ilan

     

  • Is there anything in the table to differentiate the records?  Why do you need to move the data to other tables?

  • Like this:

    ALTER TABLE

    ADD COLUMN rowid int IDENTITY(1,1)

    GO

    select *

    from table

    where rowid % 3 = 0

  • Ok it work

    now The big problem How can i do this ?

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

                fld1                      fld2                      fld3                   fld4

    1. aaaaaaaaaaaa     bbbbbbbbbbbbb       cccccccccccccccc     ddd
    2. aaaaaaaaaaaa     bbbbbbbbbbbbb       cccccccccccccccc     dddd
    3. aaaaaaaaaaaa     bbbbbbbbbbbbb       cccccccccccccccc      ddd
    4. aaaaaaaaaaaa     bbbbbbbbbbbbb       cccccccccccccccc       ddd

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

    thnks ilan

  • Something like this maybe with the structure you were given to use with the extra idenitity column (which for this cannot be missing any numbers or you will get null gaps in the output).

     

    SELECT

    CEILING(rowid/4.0) rowflow,

    MAX(CASE WHEN (rowid - 1) % 4 = 0 then val end) fld1,

    MAX(CASE WHEN (rowid - 2) % 4 = 0 then val end) fld2,

    MAX(CASE WHEN (rowid - 3) % 4 = 0 then val end) fld3,

    MAX(CASE WHEN (rowid) % 4 = 0 then val end) fld4

    FROM tblName

    GROUP BY

    CEILING(rowid/4.0)

  • thnks it work

    100%

    ilan

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

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