SQL将列数据拆分为多个列

时间:2014-05-01 20:03:58

标签: sql substring

这段代码只给我们每张专辑的第一首歌,我们需要所有这些歌

insert into musicsongs
    select distinct
    [GROUP ID], [Album 1 ],SUBSTRING ([Songs 1],1, CHARINDEX (',', [Songs 1]) -1)
from dbo.Music_Import 
    where [Songs 1] is not null
    UNION
    select distinct
    [Group ID], [Album 2 ], SUBSTRING ([Songs 2],1, CHARINDEX (',', [Songs 2])-1) 
from dbo.Music_Import
    where [Songs 2] is not null

0 个答案:

没有答案