Regd Cursor

  • Hi i have a table with column name codes:

    i have the records as abd,def,ghi---record 1

    def,gtd,wew---record 2

    i got many records here all those comed under just one column ---

    so i need to split those commas and need the distinct rows in the table ---

    i have got a logic for splitting that but what i need is that i need to use a cursor how shall i do that

    to go to each row and split it and put it in a table i got the logic for splitting jus tell me the logic for cursor how to do that .....

    Thanks,
    Chinna

    Its the Journey which gives you Happiness not the Destination-- Dan Millman

  • ok what exactly i need is

    i have acolumn with data with comma separated in the same column so now i need to remove the comma and iinsert those values into a table ---for example

    current ---column1

    abc,def,ghi

    de,ghj,kjf

    def,trg,jhu

    dhj,klw,kkk

    needed----

    abc

    def

    ghi

    de

    ghj

    kjf

    def

    trg

    jhu

    dhj

    kjw

    kkk

    ===== this is the result i needed i had a logic for splitting the comma but what all i need is how to use cursor here and fetch those each record and insert it using my logic

    here is m y logic for comma separator

    IF ( Select Left(@sc,1) ) = ','

    Select @sc = Substring(@sc, 2, Len(@sc) )

    IF ( Select Right(@sc,1) ) = ','

    Select @sc = Substring(@sc, 1, Len(@sc)- 1 )

    WHILE ( CHARINDEX(',', @sc) ) > 0

    Begin

    insert into @tbl

    select substring(@sc,1, CHARINDEX(',', @sc) - 1 )

    Select @sc = Substring(@sc, CHARINDEX(',', @sc) + 1, 8000 )

    End

    Thanks,
    Chinna

    Its the Journey which gives you Happiness not the Destination-- Dan Millman

Viewing 2 posts - 1 through 2 (of 2 total)

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