Need help on splitting CSV values

  • Hi there,

    following is the base table

    create table #sample (id int , value varchar(100))

    insert into #sample values (1,'aaa,bbb')

    insert into #sample values (2,'ccc,ddd')

    insert into #sample values (3,'aab')

    & i need the attached output

  • Take a look at this article from Jeff Moden. http://www.sqlservercentral.com/articles/Tally+Table/72993/

    ** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
  • Hi,

    HanShi is totally right.. After reading that article you'll end up with a query like the below:

    DECLARE @Sample TABLE

    (

    Id INT,

    Value VARCHAR(200)

    )

    INSERT INTO @Sample (Id,Value) VALUES (1,'aaa,bbb'),(2,'ccc,ddd'),(3,'aab')

    SELECT s.Id, item.Item

    FROM @Sample s

    CROSS APPLY [dbo].[DelimitedSplit8K](value,',') [item]

    Cheers,

    Jim.

    SQL SERVER Central Forum Etiquette[/url]

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

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