哪位高手可以帮我解读一下这个存储过程啊?(有关换车算法的)
CREATE PROC S_to_S @Station_Start nvarchar(10),
@Station_Stop nvarchar(10)
AS
SET NOCOUNT ON
DECLARE @l int
SET @l=0
SELECT LineID,StationName,
Line=CAST('('+RTRIM(LineID)+': '+RTRIM(StationName) as nvarchar(4000)),
turn=turn,
[Level]=@l
INTO # FROM 线路表
WHERE StationName=@Station_Start
WHILE @@ROWCOUNT>0
AND NOT EXISTS(SELECT * FROM # WHERE StationName=@Station_Stop)
BEGIN
SET @l=@l+1
INSERT #(Line,LineID,StationName,Turn,[Level])
SELECT
Line=a.Line+CASE
WHEN a.LineID=b.LineID THEN N'->'+RTRIM(b.StationName)
ELSE N') ∝ ('+RTRIM(b.LineID)
+N': '+RTRIM(b.StationName) END,
b.LineID,b.StationName,b.Turn,@l
FROM # a,线路表 b
WHERE a.[Level]=@l-1
AND(a.StationName=b.StationName AND a.LineID<>b.LineID
OR a.LineID=b.LineID AND(
a.Turn=b.Turn+1
OR
a.Turn=b.Turn-1))
AND LEN(a.Line)<4000
AND PATINDEX('%[ >]'+b.StationName+'[-)]%',a.Line)=0
END
SELECT N'起点站'=@Station_Start
,N'终点站'=@Station_Stop
,N'乘车线路'=Line+N')'
FROM #
WHERE [Level]=@l
AND StationName=@Station_Stop
IF @@ROWCOUNT =0 --如果未有可以到达的线路,则显示处理结果表备查
SELECT * FROM #
GO