id 是int 型
‘3908,3934‘ 是字符串,当然不可以
试试这个:
 delete YH_order WHERE (CONVERT(char(4), id) IN (ids))

解决方案 »

  1.   

    DECLARE @ids Varchar(50)
     set @ids='3908,3934'
    delete YH_order WHERE (CONVERT(char(4), id) IN (@ids))
    变量前必须有@
      

  2.   

    方法一:
    如果需要用in的写法,就需要用到动态sql写,如下:
     DECLARE @ids Varchar(50),@sql varchar(8000)
     set @ids='3908,3934'--是从参数中得到字符 '3908,3934'
     set @sql = 'delete YH_order WHERE (id IN (' + @ids + '))'
     --print @sql  -- 调试用
     exec(@sql)方法二:
    其实这样的完全可以用charindex来解决,如下: DECLARE @ids Varchar(50)
     set @ids='3908,3934'--是从参数中得到字符 '3908,3934'
    delete YH_order WHERE charindex(',' + cast(id as varchar) + ',',',' + @ids + ',') > 0
      

  3.   

    我上面说的也不行.
    这样改,变成'3908'也不在'3908,3934'这里.create table a
    (id int)
    insert into a select 243
    union select  345
    union select 123
    go
    create table #id
    (id int)
    insert into #id select 243
    union select  345select * from a  where id in (select id from #id)
    drop table #id
      

  4.   

    谢谢你 gmlxf(烛光) .我是第一次来这里提问题的,看到回复的这么快,真的很开心,谢谢大家.