行车路线演示

来源:互联网 发布:wpf开源软件 编辑:程序博客网 时间:2024/06/09 13:49

--drop table T_line
create table T_line(ID nvarchar(100),Station nvarchar(100),Orders int)
insert into T_line
select '1路','鼓楼',1 union all
select '1路','新街口',2 union all
select '1路','汽车站',3 union all
select '1路','火车站',4 union all
select '2路','新街口',1 union all
select '2路','飞机场',2 union all
select '2路','天安门',3 union all
select '3路','天安门',1 union all
select '3路','石门坎',2 union all
select '3路','驾校',3


--drop proc p_qry1
CREATE PROC p_qry1
@id nvarchar(200),
@line nvarchar(4000)
as
begin
declare @e  nvarchar(4000)
set @e=''
select @e=@e+'->'+Station  from T_line where ID=@id order by Orders
set @e=stuff(@e,1,2,'')
set @line = @e
end
GO

declare @id nvarchar(200),@line nvarchar(4000)
select @id = '1路',@line = ''
exec dbo.p_qry1 @id,@line output
select @line