I have a stored procedure where I will use @variable
in
WHERE colname LIKE(@variable)
This @variable
could be a string list representing column names, such as
EXEC usp_cols 'col1, col2, col3';
I want to split this string to list of strings in the stored procedure, so that it converts to 'col1', 'col2', 'col3'
in the stored procedure to use it in the LIKE statement:
WHERE colname LIKE('col1', 'col2', 'col3')
4条答案
按热度按时间ccrfmcuu1#
Could you please try
vuv7lop32#
As mention in comment, from 2016 you can use STRING_SPLIT. Read more about it here: https://learn.microsoft.com/en-us/sql/t-sql/functions/string-split-transact-sql?view=sql-server-ver16
It is as simple to use as this:
kxxlusnw3#
Simplest version.
SQL
u5i3ibmn4#
With a little help from the community, I think I have the result that I wanted:
Now I get the following result which can be implemented in WHERE... LIKE clause: