SQL Server split CSV into multiple rows

from
    #client_profile_temp cpt
    cross apply dbo.split(
    #client_profile_temp.interests, ',') as split  <--Error is on this line

I think the explicit naming of #client_profile_temp after you gave it an alias is a problem, try making that last line:

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

EDIT You say

I made this change and it didn’t change anything

Try pasting the code below (into a new SSMS window)

create table #client_profile_temp
(id int,
interests varchar(500))

insert into  #client_profile_temp
values
(5, 'Vodka,Potassium,Trigo'),
(6, 'Mazda,Boeing,Alcoa')

select
   cpt.id
  ,split.data
from
    #client_profile_temp cpt
    cross apply dbo.split(cpt.interests, ',') as split 

See if it works as you expect; I’m using sql server 2008 and that works for me to get the kind of results I think you want.

Any chance when you say “I made the change”, you just changed a stored procedure but haven’t run it, or changed a script that creates a stored procedure, and haven’t run that, something along those lines? As I say, it seems to work for me.

Leave a Comment