我没有发现太大的问题,不过
你有个疏漏:
if @pub_id<>''
    set @asdf='pub_id='+''''+@pub_id+''''
if @pub_minit<>''
    set @asdf=@asdf+' and minit='++''''+@pub_minit+''''
if @pub_id<>'' or @pub_minit<>''
    set @asdf=' where '+@asdf
既然是字符,查询的时候应该加上''
如 select * from mytable where col1='jack'

解决方案 »

  1.   

    if @pub_minit<>''
        set @asdf=rtrim(@asdf)+' and minit='+@pub_minit
      

  2.   

    if @pub_minit<>''
        set @asdf=rtrim(@asdf)+' and minit='+@pub_minit
      

  3.   

    既然 select 子句中的列和group by中的列是相同的,就没必要加上group by子句,order by子句也不会出错了!
    另外,exec pubs_tj 'employee','','s'这句调用相当于:
          select ... from employee where and minit=‘s’...   -- 错误很显然的
      

  4.   

    leeyoong(莫西)谢谢你的回答。可是有什么错误啊,请指教一下!
      

  5.   

    呵呵,真有意思!你难道没注意到吗?   where and minit=‘s’
                        ---------???