I have a comma-separated value (e.g. '1,2,3,4,5'
), I need to split it. I am using the STRING_SPLIT
method. My database has compatibility level 120, so I am trying to use it with USE MASTER
because MASTER
has compatibility level 150. It works as expected with the query. But when I use the same query in a transaction within a stored procedure:
USE MASTER
SELECT EquivalentUSD = SUM(value) FROM STRING_SPLIT(@CSV, ',');
I get this error:
A USE database statement is not allowed in a procedure, function or trigger.
I have thought of creating a function as an alternative approach, but I would like to know how can I use STRING_SPLIT
in a stored procedure?
I tried creating function in master, but I don’t have permission.