简单的存储过程

来源:互联网 发布:保温杯 知乎 编辑:程序博客网 时间:2024/05/22 08:09

如一串数字“3,43,23,64,234,76,5,9,14,27”进行排序输入到空表A中。
要求在表A中的排列方式如下:
num
3
5
9
14
23
27
43
64
76
234 

先创建存储过程:
create proc wsp
@sql varchar(1000)
as
create table #temp(num int)
set @sql='insert into #temp select '+replace(@sql,',',' d union all select ')
exec(@sql)
insert into a select * from #temp order by num

然后调用:
exec wsp'3,43,23,64,234,76,23,5,9,14,27'