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

前端 未结 11 2037
情书的邮戳
情书的邮戳 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:17

    Pass the comma separated list into a function that returns a table value. There is a MS SQL example somewhere on StackOverflow, damned if I can see it at the moment.

    CREATE PROCEDURE getSomething @keyList varchar(4096)
    AS
    SELECT * FROM mytbl WHERE name IN (fn_GetKeyList(@keyList))
    

    Call with -

    exec getSomething 'John,Tom,Foo,Bar'
    

    I'm guessing Sybase should be able to do something similar?

提交回复
热议问题