Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2005
    Posts
    58

    Unanswered: Procedure IN statement

    How do I format a string so that I can feed it into a Stored Procedure then be able to use it in an "in" statement in my where clause. ie.

    exec sp_mySP 'value1, value2'

    select *
    from myTable
    where myvalues in (@paramtervalues)

  2. #2
    Join Date
    Jan 2007
    Location
    California, USA
    Posts
    520
    Here is sample code for string data
    Code:
    Create procedure Test1
     (@InParms varchar(25) )
    AS
    Exec ('Select * from MyTable where AlphaField IN (' + @InParms + ')')
    Go
    Then execute it with: exec test2 '''F'', ''S'''

    And then a sample for numeric data
    Code:
    Create procedure Test2
     (@InParms varchar(25) )
    AS
    Exec ('Select * from MyTable where NumberField IN (' + @InParms + ')')
    Go
    Execute it with: exec test2 '1, 3'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •