Multiple values for a single parameter

  • I'm trying to pass multiple values from a web app via a single parameter to a stored procedure.

    I thought I could pass a list of values surrounded by double quotes from the web page like this:  execute customer " '151', '152', '153' " .  Then handle the list in the in the sp/sql :  where customer_number in (@parameter)

    That doesn't work. I'd build separate parameters but the list of individual values can range from 1 to 15.

    Help!

     

     

  • If you want to keep your parameter the way it is, you have to use dynamic sql (not recommended) in your sp. So the statement in your sp would be like

    EXEC('select * from customers where customer_number in (' + @parameter+ ')')

    Hope this helps.

     

  • Why not PARSE the multiple values for the parameter INSERT them into a #table and then do a SELECT * FROM dbo.Customers WHERE Customer_Number IN (SELECT Customer_Number FROM #table))

    Good Luck



    Good Hunting!

    AJ Ahrens


    webmaster@kritter.net

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply