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

前端 未结 11 2052
情书的邮戳
情书的邮戳 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条回答
  •  旧时难觅i
    2020-12-10 02:26

    Do you need to use a comma separated list? The last couple of years, I've been taking this type of idea and passing in an XML file. The openxml "function" takes a string and makes it like xml and then if you create a temp table with the data, it is queryable.

    DECLARE @idoc int
    DECLARE @doc varchar(1000)
    SET @doc ='
    
    
       
          
          
       
    
    
       
          
       
    
    '
    --Create an internal representation of the XML document.
    EXEC sp_xml_preparedocument @idoc OUTPUT, @doc
    -- Execute a SELECT statement that uses the OPENXML rowset provider.
    SELECT    *
    FROM       OPENXML (@idoc, '/ROOT/Customer',1)
                WITH (CustomerID  varchar(10),
                      ContactName varchar(20))
    

提交回复
热议问题