create proc sc   @a varchar(20),  @b varchar(20) ,    @c varchar(20)  
as if @b='like'exec ('select * from itm_mstr where '+@a+' like ''%'+@c+'%''')elseexec('select * from itm_mstr where '+@a+'='''+@c+'''')

解决方案 »

  1.   

    create proc sc  
     @a varchar(20),  
     @b varchar(2) ,  
     @c varchar(20)  
    as  
    if @a='itm_wldm'and @b='=' 
    begin  
       select * from itm_mstr where itm_wldm=@c  
    end 
    else if  @a='itm_wldm' and @b='like' 
    begin 
       print 'hello' 
       select * from itm_mstr where itm_wldm like '%'+@c+'%' 
    end
    else if @a='itm_wlgg'and @b='='  
    begin
       select * from itm_mstr where itm_wlgg=@c  
    end 
    else
    begin
       select * from itm_mstr where itm_wlgg like '%'+@c+'%'   
    endhello出来了吗?
      

  2.   

    create proc sc  
     @a varchar(20),  
            @b varchar(2) ,  
      @c varchar(20)  
           as  
    if @b='like'
      set @c='''%'+@c+'%'''exec('select * from itm_mstr where '+@a+' '+@b+' '+@c)
      

  3.   

    TO  tj_dns(愉快的登山者) 
    就是出不来
      

  4.   

    自己找到原因了, 原来是变量长度没设对.  
    应该是declare @b varchar(4)才对.自己能不能加分?:).....