日期:2014-05-18  浏览次数:20387 次

各位老大请帮帮忙
小弟初学SQL,现在有这样一个存储过程

create   proc_Analyse
@b   varchar(20),
@c   varchar(20)
as
select   a,b,c   from   t   where   b=@b   and   c=@c
go

在调用存储过程的时候,如果@b没有值传入,我如何能将其判断为
select   a,b,c   from   #a   where   c=@c
如果b,c都没有值传入   则判断为   select   a,b,c   from   t

哪位大哥指点下应该怎么写where后面的语句,或者传入什么参数进来让其判断为   select   a,b,c   from   t   where   b=b   and   c=c


------解决方案--------------------
create proc_Analyse
@b varchar(20),
@c varchar(20)
as
if @b is null and @c is null
select a,b,c from t
else
select a,b,c from t where b=@b and c=@c
go
------解决方案--------------------
--试试
create proc_Analyse
@b varchar(20),
@c varchar(20)
as
select a,b,c from t where b=isnull(@b,b) and c=isnull(@c,c)
go