日期:2014-05-19  浏览次数:20428 次

if else判断根据空值查询
--根据名称查询产品
create   proc   yg_GetcpInfobyMc
(
@cpname   varchar(100),
@qyname   varchar(500),
@bmname   varchar(500),
@khname   varchar(500)
)
as
if(@bmname   is   null   and   @khname   is   null)
begin
begin
select语句
end
else   if(@qyname   is   null   and   @khname   is   null)
begin
select语句
end
else   if(@qyname   is   null   and   @bmname   is   null)
begin
select语句
end
else   if(@khname   is   null   and   @qyname   is   null   and   @bmname   is   null)
begin
select语句
end
go

查询不出结果,应该怎么改啊?


------解决方案--------------------
-- try
create proc yg_GetcpInfobyMc
(
@cpname varchar(100),
@qyname varchar(500),
@bmname varchar(500),
@khname varchar(500)
)
as
if(@bmname is null and @khname is null and @cpname is not null and @qyname is not null)
begin
select语句
end

if(@qyname is null and @khname is null and @bmname is not null and @cpname is not null)
begin
select语句
end

if(@qyname is null and @bmname is null and @cpname is not null and @khname is not null)
begin
select语句
end

if(@khname is null and @qyname is null and @bmname is null and @cpname is not null)
begin
select语句
end


go