我想传一个参数 'a,b,c'来查询数据,但这是个字符串,我应该转换成:('a','b','c')才行select * form T where name in ('a','b','c')但我的参数是'a,b,c',如何实现呢在ORA中用instr函数就可以搞定,在SQL SERVER中有什么同样的方法呢,谢谢。。

解决方案 »

  1.   

    select * form T where 
    charindex(','+name+',',',a,b,c,')>0
      

  2.   

    select * form T where charindex(','+name+',',','+'a,b,c'+',')>0
      

  3.   


    DECLARE @S VARCHAR(20)SET @S='''a'',''b'',c'''
    PRINT('select * form T where name in ('+@S+')') select * form T where name in ('a','b',c')
     
      

  4.   

    DECLARE @S VARCHAR(20)SET @S='''a'',''b'',''c'''
    PRINT('select * form T where name in ('+@S+')') 
    select * form T where name in ('a','b','c')
      

  5.   


    SELECT * FROM T WHERE CHARINDEX(name,'a,b,c,d')>0