Using SQL Server 2016 and latest SSMS, I'm trying to take a csv string and split it and then insert into table-value parameter variable and I'm getting error squiggles under the string_split function.
Is what I'm doing even possible?
DECLARE @tvParam TABLE (FirstName nvarchar(50))
DECLARE @s VARCHAR(MAX) = '0152,1731'
INSERT INTO @tvParam
SELECT Value
FROM STRING_SPLIT(@s, ',')
CodePudding user response:
Not sure what build of SSMS you're using but that is just IntelliSense being not so intelligent. In anticipation of
Thankfully, you can ignore the message, which is just a parse-time warning. The code runs successfully.
CodePudding user response:
If your SQL Server version is 2016, but you can't use STRING_SPLIT
function, we need to make sure the COMPATIBILITY_LEVEL
need to be 130
or higher
STRING_SPLIT requires the compatibility level to be at least 130. When the level is less than 130, SQL Server is unable to find the STRING_SPLIT function.
ALTER DATABASE DatabaseName SET COMPATIBILITY_LEVEL = 130
After that, it might work.