| 发表于: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 |
|
|
|
|