当前位置: 代码迷 >> Sql Server >> if else判断根据空值查询,该如何处理
  详细解决方案

if else判断根据空值查询,该如何处理

热度:25   发布时间:2016-04-27 20:37:35.0
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
  相关解决方案