@ID 是一个值吗?--是的话,这样就行了select * from News Where Nid LIKE '%'+RTRIM(@ID)+'%'

解决方案 »

  1.   

    1,sqlserver不支持数组,可以用表变量代替。2,你的情况不需要拆分。有like,charindex,patindex等都可实现。但是一定要把分隔符加到前后辍上,否则会误 取。如:
    select * from news where charindex(',' + rtrim(nid) +',' , ',%' + @id + '%,')>0 
      

  2.   

    拆分字符的方法很多,2000写函数,或者动态SQL,2005用FOR XML方法,你GOOGLE一下,
    很多,或者CSDN搜索一下,不过如楼上所说,你的需求不用这样.
      

  3.   

    上面手误设nid为列名,@id为传入的串,比如1,1,3,4,5
    select * from news where charindex(',' + rtrim(nid) +',' , ',' + @id + ',')>0 
    select * from news where  ','+RTRIM(@ID)+',' like '%,' + rtrim(nid) + ',%'
      

  4.   

    select * from news where patindex('%,' + rtrim(nid) +',' , ',' + @id + ',%')>0 
      

  5.   

    上面fcuandy我按你的做,在程序中出错
    将 varchar 值 ',' 转换为数据类型为 int 的列时发生语法错误
      

  6.   

    不需要拆分字符串……
    select * from News where charindex(','+rtrim(@id)+',',','+rtrim(Nid)+',')>0
      

  7.   

    好了,谢谢各位了,再次谢谢szx1999 ,fcuandy ,wufeng4552 终于实现了这就去结帖了