请问高手们,我下面的存储过程有什么问题,怎么都是没有记录查询处理啊
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
我执行上面的存储过程怎么都查询出了全部记录啊?
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
我执行上面的存储过程怎么都查询出了全部记录啊?
!=null换成is not null
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
@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
@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
pno pname
1212 34234
我执行text null,'3',怎么没有记录的啊
@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
@pno char(20),
@pname char(20)
应写成:
create proc text
@pno varchar(20),
@pname varchar(20)