当前位置: 代码迷 >> Sql Server >> 各位老大请帮帮忙解决方案
  详细解决方案

各位老大请帮帮忙解决方案

热度:31   发布时间:2016-04-27 15:48:13.0
各位老大请帮帮忙
小弟初学SQL,现在有这样一个存储过程

create   proc_Analyse
@b   varchar(20),
@c   varchar(20)
as
select   a,b,c   from   t   where   [email protected]   and   [email protected]
go

在调用存储过程的时候,[email protected],我如何能将其判断为
select   a,b,c   from   #a   where   [email protected]
如果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 [email protected] and [email protected]
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
  相关解决方案