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

存储过程的高级问题,如何处理?
创建一个存储过程PX,完成对任意五个数的排序

------解决方案--------------------



create proc pz_PP_NumericOrder(
@X01 decimal,
@X02 decimal,
@X03 decimal,
@X04 decimal,
@X05 decimal)
as

declare @str nvarchar(100)
set @str= ' '
select @str=@str+cast(a as nvarchar)+ '> = '
from
(select @X01 as a
union all
select @X02
union all
select @X03
union all
select @X04
union all
select @X05) as p
order by a desc
set @str=substring(@str,1,len(@str)-2)
print @str

GO

exec pz_PP_NumericOrder 1,55,9,9,7
------解决方案--------------------
升序:

create proc proc_Order(
@a decimal,
@b decimal,
@c decimal,
@d decimal,
@e decimal)
as

declare @str nvarchar(100)
select * from
(
select @a col_order
union all
select @b
union all
select @c
union all
select @d
union all
select @e
)t
order by col_order
go


exec proc_Order 4,5,34,98,7

------
col_order
4
5
7
34
98


------解决方案--------------------
create proc proc_Order(
@a decimal,
@b decimal,
@c decimal,
@d decimal,
@e decimal)
as

declare @str nvarchar(100)
select * from
(
select @a col_order
union all
select @b
union all
select @c
union all
select @d
union all
select @e
)t
order by newid()--随机排序