1

I have a string like so:

DECLARE @columnCamera varchar(MAX) = 'aaa,bbb,ccc'

and I am trying to split these and loop through, I am stuck on the splitting part:

SELECT * FROM STRING_SPLIT(@columnCamera, ',')

But I get this error:

Invalid object name 'STRING_SPLIT'.

What is the proper way to split a string and loop through it?

user979331
  • 11,039
  • 73
  • 223
  • 418
  • what version of sql are you using? – TZHX May 02 '18 at 20:27
  • SQL Server 2014 – user979331 May 02 '18 at 20:29
  • 3
    The `STRING_SPLIT` function only became available in SQL Server 2016, so I'm afraid you don't have that function available. – TZHX May 02 '18 at 20:30
  • I get that, what is the proper way to split a string in SQL...I did some digging and it looks super hard – user979331 May 02 '18 at 20:31
  • It's supposed to be hard. CSV data is anathema to good SQL practice. – Joel Coehoorn May 02 '18 at 21:01
  • Please read [this question](https://stackoverflow.com/q/50068426/5089204). It was closed as duplicate and it is a perfect duplicate to this itself (including the existing sub-optimal answer). – Shnugo May 02 '18 at 21:59
  • I voted to close this as it is a duplicate. One hint: I'd suggest to read the younger answers rahter than the highest rated. They were good at their times but are outdated.... – Shnugo May 02 '18 at 22:00

0 Answers0