求一个存储过程 高手请进 急用

anthit 2006-06-08 09:04:29
两个表
表1:station
StationID Int 4 车站编号
StationName Varchar 20 火车站名

表2:train
TrainID int 4 车次编号
TrainNo Nvarchar 10 火车车次
StartTime datetime 8 出发时间
EndTime datetime 8 到站时间
StartStationID int 4 出发站编号
EndStationID int 4 终点站编号

其中的 表2中的出发站编号 终点站编号 就是表1中的车站编号
想写一个存储过程,得到下面的结果:
车次编号 火车车次 出发时间 到站时间 始发站 终点站

急用,谢谢


...全文
180 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
anthit 2006-06-09
  • 打赏
  • 举报
回复
thanks
paoluo 2006-06-08
  • 打赏
  • 举报
回复
這個問題,用Inner Join的效率就要高些了。 :)

dssw 2006-06-08
  • 打赏
  • 举报
回复
好快!
LouisXIV 2006-06-08
  • 打赏
  • 举报
回复
^^

除了Inner Join以外不喜欢用链接数据库

子查询和Exists用得比较多
paoluo 2006-06-08
  • 打赏
  • 举报
回复
你又用子查詢了。 :)
LouisXIV 2006-06-08
  • 打赏
  • 举报
回复
补一个逗号-_-
create procedure sp_Train(@StartStation int,@EndStation int)
as

select
TrainID as 车次编号,
TrainNo as 火车车次,
StartTime as 出发时间,
EndTime as 到站时间,
(select StationName from station where StationID=@StartStation) as 始发站,
(select StationName from station where StationID=@EndStation) as 终点站
from
train
where
StartStationID=@StartStation
and EndStationID=@EndStation
LouisXIV 2006-06-08
  • 打赏
  • 举报
回复
create procedure sp_Train(@StartStation int,@EndStation int)
as

select
TrainID as 车次编号,
TrainNo as 火车车次,
StartTime as 出发时间,
EndTime as 到站时间
(select StationName from station where StationID=@StartStation) as 始发站,
(select StationName from station where StationID=@EndStation) as 终点站
from
train
where
StartStationID=@StartStation
and EndStationID=@EndStation
paoluo 2006-06-08
  • 打赏
  • 举报
回复
--寫成存儲過程的話

--建立存儲過程
Create ProceDure GetTrain(@StartStationID Int, @EndStationID Int)
As
Begin
Select
A.TrainID As 车次编号,
A.TrainNo As 火车车次,
A.StartTime As 出发时间,
A.EndTime As 到站时间,
B.StationName As 始发站,
C.StationName As 终点站
From train A
Left Join station B
On A.StartStationID=B.StationID
Left Join station C
On A.EndStationID=C.StationID
Where A.StartStationID=@StartStationID And A.EndStationID=@EndStationID
End
GO
--調用
EXEC GetTrain 3,7
paoluo 2006-06-08
  • 打赏
  • 举报
回复

Select
A.TrainID,
A.TrainNo,
A.StartTime,
A.EndTime,
B.StationName,
C.StationName
From train A
Left Join station B
On A.StartStationID=B.StationID
Left Join station C
On A.EndStationID=C.StationID
Where A.StartStationID=3 And A.EndStationID=7
anthit 2006-06-08
  • 打赏
  • 举报
回复
忘了 说了 传进来的参数就是
出发站编号 终点站编号

34,837

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧