Fix - Invalid object name STRING_SPLIT In SQL Server

The STRING_SPLIT function is introduced in SQL Server 2016 and the function seems not working on many of the machines running on old SQL Server versions. The other day, I was working on the older version of SQL Server (SQL Server 2012) and I happen to encounter the error “Invalid object name STRING_SPLIT”.

Additionally, if you notice, the function does not work on versions of SQL Server 2014 or older.

I was trying to run the below simple SELECT on the STRING_SPLIT and encountered the error.

select * from STRING_SPLIT ('hospital,office,home',',')

Invalid Object Name STRING SPLIT In SQL Server

FIX:

The reason for this erroring out is due to the compatibility of your computer to the SQL Server version. The SQL Server doesn’t feature itself to automatically set the compatibility. All we must do is to change and fix the compatibility to SQL Server versions respectively and it works fine. 

To change the compatibility of a SQL Server version, please find the general syntax below:

ALTER DATABASE [your db name]
SET COMPATIBILITY_LEVEL = 140 -- 140 Compatibility level is for SQL Server 2017

SQL Server Compatibility Levels






Note: Please change the compatibility level as per the image and your requirement. 

Once I changed the compatibility level of my SQL Server version, the SELECT query that I ran previously started working without any issues. 

Invalid Object Name STRING SPLIT In SQL Server

0 comments: