请问高手们,我下面的存储过程有什么问题,怎么都是没有记录查询处理啊 
create proc text
@pno char(20),
@pname char(20)
as
if @pno=null and @pname=null
select * from product
else if @pno!=null and @pname=null
select * from product where pno=@pno
else if @pno=null and @pname!=null
select * from product where pname=@pname
else
select * from product where pno=@pno and pname=@pname
go
我执行上面的存储过程怎么都查询出了全部记录啊?

解决方案 »

  1.   

    把=null换成is null
    !=null换成is not null
      

  2.   

    改成:
    create proc text
    @pno char(20)=null,
    @pname char(20)=null
    as
    if @pno is null and @pname is null
    select * from product
    else if @pno is not null and @pname is null
    select * from product where pno=@pno
    else if @pno is null and @pname is not null
    select * from product where pname=@pname
    else
    select * from product where pno=@pno and pname=@pname
    go
      

  3.   

    create proc text
    @pno char(20),
    @pname char(20)
    as
    if @pno is null and @pname is null
    select * from product
    else if @pno is not null and @pname is null
    select * from product where pno=@pno
    else if @pno is null and @pname is not null
    select * from product where pname=@pname
    else
    select * from product where pno=@pno and pname=@pname
    go
      

  4.   

    如果pname使用like该如何写呢 当pname is not null时
      

  5.   

    create proc text
    @pno char(20),
    @pname char(20)
    as
    if @pno is null and @pname is null
    select * from product
    else if @pno is not null and @pname is null
    select * from product where pno=@pno
    else if @pno is null and @pname is not null
    select * from product where pname like +'%'+@pname+'%'
    else
    select * from product where pno=@pno and pname like +'%'+@pname+'%'
    go
      

  6.   

    没有用啊
    pno   pname
    1212  34234
    我执行text null,'3',怎么没有记录的啊
      

  7.   

    create proc text
    @pno char(20),
    @pname char(20)
    as
    if @pno is null and @pname is null
    select * from product
    else if @pno is not null and @pname is null
    select * from product where pno=@pno
    else if @pno is null and @pname is not null
    select * from product where pname like '%'+@pname+'%'
    else
    select * from product where pno=@pno and pname like +'%'+@pname+'%'
    go
      

  8.   

    create proc text
    @pno char(20),
    @pname char(20)
    应写成:
    create proc text
    @pno varchar(20),
    @pname varchar(20)