如何写这种存贮过程?(急)

阿阌 2003-04-30 10:44:40
需要有5个参数,这些参数可以一个或多个为0(都是int类型的)就SELECT相应的记录集,具体如下:
@A int,
@B int,
@C int,
@D int,
@E int
如果@A = 0,就返回以@B,@C,@D,@E为条件SELECT的结果,如果@A,@B都为0,就返回@C,@D,@E为条件SELECT的结果,其它依此类推.

哪为老大帮帮我吧!!!
...全文
25 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
tingquan 2003-04-30
  • 打赏
  • 举报
回复
CREATE PROCEDURE mysp_test
@a int,
@b int,
@c int,
@d int,
@e int
AS
if @a=0 and @b=0
begin
SELECT *
FROM tablename WHERE col_c= @c and col_d=@d and col_e=@e
end
else
begin
if @a=0
select * from tablename where col_b=@b and col_c= @c and col_d=@d and col_e=@e
end


---是这样的吧
longji 2003-04-30
  • 打赏
  • 举报
回复
create procedure lfy
@a int=0,@b int=0,@c int=0,@d int=0,@e int=0,
@a1 int output,
@b1 int output,
@c1 int output,
@d1 int output,
@e1 int output
as
begin
if @a=0
begin
select @a1=99999
select @b1=2
select @c1=3
select @d1=4
select @e1=5
end
if @a=0 and @b=0
begin
select @a1=99999
select @b1=99999
select @c1=3
select @d1=4
select @e1=5
end
--下面依次真写就行了,不过这样的条件是有问题的,这个要求最好在调用过程时加上

end
阿阌 2003-04-30
  • 打赏
  • 举报
回复
自己推一下,谢谢各位了!

22,298

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧