我在存储过程里使用下面语句update table1 set a = @a where id in ( @id )其中@id是 Nvarchar(1000)我传过去的字符串为  1,2,3,4报的错误是不能将  '1,2,3,4' 转化为数字型是不是传输的字符串自动给加上  '' 这个符号?请问,我该如何处理?谢谢各位。

解决方案 »

  1.   

    exec('update table1 set a = @a where id in ('+@id+')') 
      

  2.   

    update table1 set a=@a where charindex(','+rtrim(id)+',' , ','+@id+',') 
      

  3.   

    exec('update table1 set a = '+''''+@a+''''+' where id in ( '+@id+' )') 
      

  4.   


    我也是用下面的语句的
    exec('update table1 set a ='+@a+' where id in ('+@id+')') 因为我需要更新的比较多,就是 a ='+@a+' 这个会很多,
    但是,结果老是报 '31' 附近有语法错误。可是我查遍了传过去的值,也没有一个是 '31' 的啊请教了
      

  5.   

    楼上采取charindex方法的不错。 
      

  6.   

    个人不喜欢用charindex
    我更喜欢用replace函数SQL codeexec('update table1 set a = @a where id in ('''+ replace(@id,',',''',''' )+''' ') 
      

  7.   

    update table1 set a=@a where charindex(','+rtrim(id)+',' , ','+@id+',') 
    最喜欢的就是这种了!!
      

  8.   

    print 'update table1 set a ='+@a+' where id in ('+@id+')'这句话,看看
      

  9.   


    update table1 set a=@a where charindex(','+rtrim(id)+',' , ','+@id+',') 支持这个
      

  10.   

    exec('update table1 set a ='+quotename(@a, '''')+' where id in ('+@id+')')
      

  11.   

    update table1 set a = @a where id in 
    (
    SELECT LTRIM(RTRIM(B.x.value('.','int')))
    FROM(
    SELECT CONVERT(XML,'<v>'+REPLACE(@id,',','</v><v>')+'</v>') AS s
    ) AS A
    CROSS APPLY A.s.nodes('v') AS B(x)
    )
      

  12.   


    update table1 set a=@a where charindex(','+rtrim(id)+',' , ','+@id+',') 
      

  13.   

    update table1 set a=@a where charindex(','+rtrim(id)+',' , ','+@id+',')能帮忙解释下么?  charindex执行后返回 int类型
    跟在where语句后面
      

  14.   


    update table1 set a=@a where charindex(','+rtrim(id)+',' , ','+@id+',')  >0
    应该是这样的!@