SQL Server将CSV分成多行

我知道之前曾有人问过这个问题,但由于某种原因我无法使其正常工作。


我正在使用来自此SQL Team线程(第二篇文章)和以下查询的split函数。


--This query converts the interests field from text to varchar

select

    cp.id

    ,cast(cp.interests as varchar(100)) as interests

into #client_profile_temp

from

    client_profile cp


--This query is supposed to split the csv ("Golf","food") into multiple rows            

select

    cpt.id

    ,split.data

from

    #client_profile_temp cpt

    cross apply dbo.split(

    cpt.interests, ',') as split  <--Error is on this line

但是我正在


Incorrect syntax near '.'

我在上面标记的错误。


最后,我要


ID              INTERESTS

000CT00002UA    "Golf","food"

成为


ID              INTERESTS

000CT00002UA    "Golf"

000CT00002UA    "food"

我正在使用SQL Server 2008,并将答案基于此StackOverflow问题。我对SQL还是很陌生,所以其他任何智慧的话也将不胜感激。


Qyouu
浏览 568回答 3
3回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

SQL Server