您的位置:程序门 -> ms-sql server -> 基础类



谁能给详细解释一下这段存储过程


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


谁能给详细解释一下这段存储过程
发表于:2007-07-21 20:52:50 楼主
create   proc   p_qry
@station_start   nvarchar(10),
@station_stop     nvarchar(10)
as
set   nocount   on
declare   @l   int
set   @l=0
select   id,station,
line=cast( '( '+rtrim(id)+ ':   '+rtrim(station)   as   nvarchar(4000)),
orders=orders,
[level]=@l
into   #   from   t_line
where   station=@station_start
while   @@rowcount> 0  
and   not   exists(select   *   from   #   where   station=@station_stop)
begin
set   @l=@l+1
insert   #(line,id,station,orders,[level])
select  
line=a.line+case
when   a.id=b.id   then   n '-> '+rtrim(b.station)
else   n ')   =>   ( '+rtrim(b.id)
+n ':   '+rtrim(b.station)   end,
b.id,b.station,b.orders,@l
from   #   a,t_line   b
where   a.[level]=@l-1
and(a.station=b.station   and   a.id <> b.id
or   a.id=b.id   and(
a.orders=b.orders+1
or
a.orders=b.orders-1))
and   len(a.line) <4000
and   patindex( '%[   > ] '+b.station+ '[-)]% ',a.line)=0
end
select   n '起点站 '=@station_start
,n '终点站 '=@station_stop
,n '乘车线路 '=line+n ') '  
from   #  
where   [level]=@l  
and   station=@station_stop
if   @@rowcount   =0   --如果未有可以到达的线路,则显示处理结果表备查
select   *   from   #
go
发表于:2007-07-22 11:15:041楼 得分:0
是不是分太少了,没人花时间帮你分析呢..
一般分析这个我是带个常量进去一条一条的在查询分析器中运行看结果的...
帮你顶...
发表于:2007-07-22 12:19:372楼 得分:0
这是个求最短乘车路线的过程,你可以看一下:
http://blog.csdn.net/simonhehe/archive/2007/06/12/1649489.aspx
发表于:2007-07-23 15:22:393楼 得分:0
那里不明白呢?
发表于:2007-07-23 15:29:304楼 得分:0
在对象浏览器里打到存储过程,再调试一下


快速检索

最新资讯
热门点击