Sql Server 2016, Invalid Object Name 'String_Split'

Sql Server 2016, Invalid Object Name 'String_Split'

In SQL Server 2016 I receive this error with STRING_SPLIT function

SELECT * FROM STRING_SPLIT('a,b,c',',')

Error:

Invalid object name 'STRING_SPLIT'.

6

5 Answers

Make sure that the database compatibility level is 130

you can use the following query to change it:

ALTER DATABASE [DatabaseName] SET COMPATIBILITY_LEVEL = 130

As mentioned in the comments, you can check the current compatibility level of a database using the following command:

SELECT compatibility_level FROM sys.databases WHERE name = 'Your-Database-Name';
6

I was using Split_string, which felt grammatically correct in English, but my old eyes didn't see that it should be STRING_SPLIT ... so, if you're a bit mentally challenged like me, then check you've typed the command the right way! :)

If you can't change the COMPATIBILITY_LEVEL of the database you are working in, you can try looking at other databases on the same server to find one with a higher COMPATIBILITY_LEVEL. I found that the "master" database on my target server was at COMPATIBILITY_LEVEL = 140, so I connected to that database, and then executed my query, which actually ran against (fully qualified) tables in other databases on the server whose COMPATIBILITY_LEVEL was less than 130. It worked! Just query the various databases on your server with

SELECT compatibility_level  FROM sys.databases WHERE name = '<database_name>'; 

to find one that is >= 130.

You need to change the Compatibility Level of your Database. to do so try below Query and Change you compatibility level to 150.

ALTER DATABASE [Database_Name] SET COMPATIBILITY_LEVEL = 150

2

I know that some big companies and their developers will be very careful about altering database since it would be total a chaos. Here I spent 30 minutes to get this done. This can be used with both old and new version of SQL Servers and their databases. I know it is a big query but gets the job done without problem.

DECLARE @String varchar(1024)
DECLARE @Pos int
DECLARE @Keywords TABLE(string varchar(25)) 
DECLARE @Key varchar(25)
SET @String = 'your string is going to come here'
SET @Pos = 1
WHILE (@Pos > 0)
BEGIN
    SET @Pos = PATINDEX('% %', @String)
    SET @Key = SUBSTRING(@String, 0, @Pos)
    IF (@Pos = 0)
        BEGIN
            INSERT INTO @Keywords (string) VALUES(@String)
        END
    ELSE
        BEGIN
            INSERT INTO @Keywords (string) VALUES(@Key)
        END
    SET @String = LTRIM(SUBSTRING(@String, @Pos, (SELECT LEN(@String))))
END 

SELECT * FROM @Keywords

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Sarah Jenkins
Author

Sarah Jenkins

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.