存储过程中的一句sql  where a.fwpid=1 and b.fbh in(@abc) 
@abc 变量的值为 'A班','B班','C班'由于引号问题总是出错。 不知道@abc的值如何来设置
 

解决方案 »

  1.   

    charindex(','+ b.fbh +',' , ',' + @abc + ',') > 0
      

  2.   

    where a.fwpid=1 and b.fbh in(@abc) and charindex(','+ b.fbh +',' , ',' + @abc + ',') > 0
      

  3.   

    where a.fwpid=1 and charindex(','''+b.fbh+''',',','+@abc+',')>0  
      

  4.   

    拷贝错了.where a.fwpid=1 and charindex(','+ b.fbh +',' , ',' + @abc + ',') > 0
      

  5.   

    如果变量值为:'A班','B班','C班'用3楼,
    如果变量值为:'A班,B班,C班',2L可用.
      

  6.   

    按照你的方式写的存储过程,首先是一个动态SQL语句,
    需要使用字符串拼接的方式连成完整的SQL语句
    set @abc='''A班'',''B班'',''C班''';
    'where a.fwpid=1 and b.fbh in('+@abc+')';
      

  7.   

    我也跟着看错,再写一个吧:exec('select * from tb where a.fwpid=1 and b.fbh in('+@abc+')')
      

  8.   

    我说的不好,大家可能都理解错了。
    通过选择条件查询筛选出不同的班次dropdownlist 的参数执行的存储过程存储过程中 变量所在位置
    这样查询 查不出来结果。主要问题是
    设置的不好,单引号的问题吧。我就是想问下Dropdownlist如何设置参数.或者根据我的需求 有别的好办法吗。
      

  9.   

    in 内为数据集,不能直接用变量,可按#1楼用charindex
    或用动态查询
    --动态查询实现
    declare @sql varchar(500),@abc varchar(200)
    set @sql='select * from 表 where a.fwpid=1 and b.fbh in('+@abc+')'
    exec(@sql)