Pass Multiple Values to a variable on a SP

  • Hi All

    I have created a SP that accepts a variable as input, can i pass multiple values SP the SP returns result for all

    EXEC SPNAME 'SAM'

    Say the above SP returns details about SAM, can i get details for SAM and Andy using the same SP, by passing 2 values into the SP

    is this possible ??

    Please suggest me 🙂

  • typically, you might pass a comma delimited string to the procedure, and the proc then uses one of the many SPLIT functions in the Scripts section here on SSC to turn teh comma delimited list into a table;

    exec sp_yourproc('Bill,Andy,Doug,Bob)

    which does something like SELECT FROM USERS WHERE USERNAME IN (SELECT ELEMENT FROM dbo.Split(@CommaDelimitedlist,',') )

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thanks Lowell, that's a nice plan :), will try that one

  • You could also use dynamic sql to do this.

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

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