How To Split The Data...Using The Stored Procedure...

  • Hi..

    I Want to Spliting the Data for The Following Table. Using The Stored Procedure....

    Create Table Source (Owner_Name varchar(100),SeatNo Varchar(100))

    insert into Source values ('A','10,11,12'),('B','20,21,22'),('C','30,31,32')

    select * from source

    A10,11,12

    B20,21,22

    C30,31,32

    But My Requirement Structure Sholud like below Mentioned..

    NameNo

    A10

    A11

    A12

    B20

    B21

    B22

    C30

    C31

    C32

    Thanks & Regards,

    K.D.Saravanan

  • You need to apply a good splitter to each CSV. Like this.

    SELECT s.Owner_Name,

    SeatNo = split.Item

    FROM dbo.Source s

    CROSS APPLY dbo.DelimitedSplit8K(s.SeatNo,',') split

    ;

    You can get the DelimitedSplit8K splitter from the following article which also explains why you shouldn't use other types of splitters.

    http://www.sqlservercentral.com/articles/Tally+Table/72993/

    --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)

  • Thank you sir...

    Thank you so much....

    Take Care...

    Regards,

    K.D.Saravanan

  • sarwaanmca (4/14/2013)


    Thank you sir...

    Thank you so much....

    Take Care...

    Regards,

    K.D.Saravanan

    Thank you for the feedback. 🙂

    --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