How to pass a comma separated list to a stored procedure?

前端 未结 11 2049
情书的邮戳
情书的邮戳 2020-12-10 01:32

So I have a Sybase stored proc that takes 1 parameter that\'s a comma separated list of strings and runs a query with in in an IN() clause:

CREATE PROCEDURE          


        
11条回答
  •  半阙折子戏
    2020-12-10 02:27

    This is a little late, but I had this exact issue a while ago and I found a solution.

    The trick is double quoting and then wrapping the whole string in quotes.

    exec getSomething """John"",""Tom"",""Bob"",""Harry"""
    

    Modify your proc to match the table entry to the string.

    CREATE PROCEDURE getSomething @keyList varchar(4096)
    AS
    SELECT * FROM mytbl WHERE @keyList LIKE '%'+name+'%' 
    

    I've had this in production since ASE 12.5; we're now on 15.0.3.

提交回复
热议问题