日期:2014-05-18  浏览次数:20525 次

关于游标的查询
@vouchid   varchar(1000)= ' '       //这是我从前台输入的参数

//我想声明一个游标
  DECLARE   cursor_for   CURSOR   FOR
  select   *   from   t   where   id   in   (   @vouchid   )   //但是这样写是不对的,因为@vouchid是字符类型的,
@vouchid= '1,2,3,4 '     //这种形式的
id是整型变量

应该怎样写才对?(直接在SQL语句里改,不要把@vouchid的数据放到表里)


------解决方案--------------------
修正一下
select * from t where charindex( ', '+rtrim(id)+ ', ' , ', '+@vouchid+ ', ')> 0