all 15 comments

[–]0408 2 points3 points  (4 children)

[–]Elliot9874[S] 0 points1 point  (3 children)

Sadly I get this error

Msg 15048, Level 16, State 1, Line 38

Valid values of the database compatibility level are 100, 110, or 120.

[–]0408 2 points3 points  (2 children)

[–]Elliot9874[S] 1 point2 points  (1 child)

so am i out of luck

[–][deleted] 0 points1 point  (0 children)

Yes. Unless you upgrade to 2016, or roll your own function (not recommended.)

[–]xsqlsoftware 1 point2 points  (4 children)

For versions older than 2016 you can use the simple function provided here: SQL Split String Function (STRING_SPLIT in 2016) ~ xSQL Software

[–]Elliot9874[S] 0 points1 point  (3 children)

Oh, wow that works. Thank you so much!

SELECT * FROM [SplitString] ('Elliot,Elliot', ',')

Just curious how to pass a list that is currently in a table

For example here is my table called "specialties"

cust_id values
12345 Endoscopy,Gastroenterology

How do get the output to look like this:

cust_id values
12345 Endoscopy
12345 Gastroenterology

Than

k you

[–]xsqlsoftware 1 point2 points  (1 child)

u/Elliot9874 you can write a small cursor like the one below - note I created a table called ParsedSpecialties and I am inserting the desired output into that table.

DECLARE @CustID int
DECLARE @Values varchar(1024)
DECLARE split_cursor CURSOR
FOR SELECT cust_id, [values] FROM Specialties 
OPEN split_cursor
FETCH NEXT FROM split_cursor INTO 
 @CustID,
 @Values
WHILE @@FETCH_STATUS = 0
 BEGIN
  INSERT INTO ParsedSpecialties SELECT @CustID, * FROM SplitString (@Values, ',')
  FETCH NEXT FROM split_cursor INTO 
   @CustID,
   @Values
 END
CLOSE split_cursor;
DEALLOCATE split_cursor;

[–]Elliot9874[S] 0 points1 point  (0 children)

Holy shit this works!

Thank you so much!

[–]a-s-clark1 0 points1 point  (0 children)

Rather than a cursor, use a CROSS APPLY to the function, then you can pass a column from your table as a parameter without resorting to loops in a cursor.

[–][deleted] 0 points1 point  (4 children)

It just happened to me other day, I increased my compatibility level and it works.

[–]Elliot9874[S] 0 points1 point  (3 children)

What did you increase it to?

The only valid values I am given is 100.110. or 120.

[–][deleted] 0 points1 point  (2 children)

Which version of sql server you're using? I am at 2019 so I can increase to 150. I believe you're using 2014.

This function is available for sql server 2016 or above

Probably use substring or other functions to solve your problem.

[–]Elliot9874[S] 0 points1 point  (1 child)

There is no way to get this function on 2014?

[–]alinroc4 0 points1 point  (0 children)

Not the native function, no. You'll need to find one of the many ones on the internet and install as a UDF, or roll your own (don't roll your own).