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

双参数的存储过程问题
存储过程设置了两个参数,
有两类用户,在调用该存储过程时均只对一个参数进行赋值,希望另一个参数不起作用,怎么处理?
例如:对于两个字段id和name分别设置参数,用户一进行数据检索,只对id赋值,不管name的值,
用户二则刚好相反,只对name赋值,不管id

用两个不同的存储过程是一个办法,但是能不能只用一个存储过程就实现这种要求?

------解决方案--------------------
create proc test
@id int=null,
@name varchar(10)=null
as
if @id is null and @name is null
print 'id is null and name is null '
else if @id is null and @name is not null
print 'id is null and name is not null '
else if @id is not null and @name is null
print 'id is not null and name is null '
else
print 'id is not null and name is not null '

go
test 1
test @name= 'fds '
------解决方案--------------------
如楼上
------解决方案--------------------
我也同意,如果参数给个默认值就可以了!
------解决方案--------------------
一楼正解
------解决方案--------------------
一楼的正解啦,不过楼主要主要你的两个字段的默认值最好别设成null