首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

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

2012-01-28 
各位老大请帮帮忙小弟初学SQL,现在有这样一个存储过程createproc_Analyse@bvarchar(20),@cvarchar(20)asse

各位老大请帮帮忙
小弟初学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

热点排行