日期:2014-05-18 浏览次数:20640 次
IF OBJECT_ID('GetBus') is not null drop function GetBus GO /*创建公交车路线直达查询的函数*/ /*其应返回一张表*/ /*路线*/ /* 702*/ CREATE FUNCTION GetBus ( @StartStation nvarchar(50), --输入乘客乘车的起始站 @EndStation nvarchar(50) --输入乘客乘车的终点站 ) RETURNS TABLE AS BEGIN DECLARE @temp TABLE(路线 nvarchar(50)) INSERT INTO @temp(路线) SELECT StRoute FROM dbo.ByOneBus(@StartStation,@EndStation) IF(@temp IS NOT NULL) RETURN @temp ELSE DECLARE @temp TABLE(车次 nvarchar(50),转乘站点 nvarchar(50),转乘车次 nvarchar(50)) INSERT INTO @temp(车次,转乘站点,转乘车次) SELECT StRoute,MidStation,EndRoute FROM dbo.ByTwoBus(@StartStation,@EndStation) IF(@temp IS NOT NULL) RETURN @temp ELSE DECLARE @temp TABLE(车次 nvarchar(50),转乘站点 nvarchar(50),转乘车次 nvarchar(50),转乘站点2 nvarchar(50),转乘车次2 nvarchar(50)) INSERT INTO @temp(车次,转乘站点,转乘车次,转乘站点2,转乘车次2) SELECT StRoute,MidStation1,MidRoute,MidStation2,EndRoute FROM dbo.ByThreeBus(@StartStation,@EndStation) RETURN @temp END