Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'.

like image 575
Victor Hugo Terceros Avatar asked Nov 09 '17 15:11

Victor Hugo Terceros


People also ask

Why does SQL say invalid object name?

This typically means 1 of 2 things... you've referenced an object (table, trigger, stored procedure,etc) that doesn't actually exist (i.e., you executed a query to update a table, and that table doesn't exist). Or, the table exists, but you didn't reference it correctly...

How do I find the compatibility level in SQL Server?

Right-click the database, and then select Properties. The Database Properties dialog box opens. In the Select a page pane, select Options. The current compatibility level is displayed in the Compatibility level list box.

How split comma separated values in SQL query?

Split comma-separated value string in a column. SELECT ProductId, Name, value FROM Product CROSS APPLY STRING_SPLIT(Tags, ','); Here is the result set. The order of the output may vary as the order is not guaranteed to match the order of the substrings in the input string.


2 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'; 
like image 140
Yahfoufi Avatar answered Sep 24 '22 08:09

Yahfoufi


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! :)

like image 25
Toad Avatar answered Sep 24 '22 08:09

Toad