本帖最后由 hank5658 于 2012-04-18 15:31:34 编辑

解决方案 »

  1.   

    create procedure hycx
    @a int,
    @b int
    as 
      declare @sql nvarchar(800)
      set @sql=N'select * from hyxx where 1=1'
      if @a<>0 and @b<>0 
        set @sql=@sql+N' and flag=0 and jf<>0 and je<>0'
      else if @a<>0 and @b=0
        set @sql=@sql+N' and flag=0 and jf<>0'
      else if @a=0 and @b<>0
      .....  exec (@sql)
      

  2.   

    你这种情况不需要用到那么多参数,用一个就够了。
    create procedure hycx
      @A int
    AS
      if @A=0 
         select * from ...
      else if @A=1 
         select * from ...
      else if @A=2
         select * from ...
      else ...
         ...
      

  3.   

     select * from hyxx where flag=0 and (@a = 0 or jf<>0) and(@b=0 or je<>0');