How to use multiple values in a single query parameter

  • OK, you might have guessed that I am new to this.

    Here is something I tried, it doesn't work but might illustrate what I am trying to do:

    declare @ids varchar

    SET @ids = '(1,2)'

    SELECT

    SATA_AllocationObject.*, Id AS Expr1

    FROM

    SATA_AllocationObject

    WHERE

    (Id IN @ids)

    Thanks

    Mark

  • declare @ids varchar(5)

    SET @ids = '1,2'

    declare @sql varchar(1000)

    select @sql = 'SELECT SATA_AllocationObject.*, Id AS Expr1'

    select @sql = @sql + ' FROM SATA_AllocationObject'

    select @sql = @sql + ' WHERE Id IN (' + @ids + ')'

    exec (@sql)

     

    But use only if you are sure you are not subject to SQL injection.


    N 56°04'39.16"
    E 12°55'05.25"

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

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