Using an 'IN' operator with a SQL Command Object and C# 2.0

后端 未结 3 792
离开以前
离开以前 2021-01-19 05:15

I would like to call a sql statement such as:

Select * From Table Where Column in (\'value1\', \'value2\', \'value3\')

Is it as simple as s

3条回答
  •  失恋的感觉
    2021-01-19 05:31

    if you only have three parameters for the in clause then yes you can use the parameters. Otherwise you can build dynamic SQL (Be careful of SQL injection attacks).

    Another approach is to create a UDF which takes a delimited string and returns a table. then you could modify your query to be:

    select * from 
    table inner join
    dbo.fn_stringToTable(@params)
    

提交回复
热议问题