Sql 真的可以在那里做任何事情,只是让它更难阅读。很酷,谢谢你,无可否认,开始-结束只是我在学习别人告诉我的基本上如果你有多个查询封装它时养成的一个坏习惯。是的,这也行得通,但是你不需要有一个表,你可以只选择@arr0,+其他变量..--顺便说一句,begin+
Sql 真的可以在那里做任何事情,只是让它更难阅读。很酷,谢谢你,无可否认,开始-结束只是我在学习别人告诉我的基本上如果你有多个查询封装它时养成的一个坏习惯。是的,这也行得通,但是你不需要有一个表,你可以只选择@arr0,+其他变量..--顺便说一句,begin+,sql,sql-server,tsql,stored-procedures,Sql,Sql Server,Tsql,Stored Procedures,真的可以在那里做任何事情,只是让它更难阅读。很酷,谢谢你,无可否认,开始-结束只是我在学习别人告诉我的基本上如果你有多个查询封装它时养成的一个坏习惯。是的,这也行得通,但是你不需要有一个表,你可以只选择@arr0,+其他变量..--顺便说一句,begin+end块除了使它更难阅读之外,实际上没有任何作用。很酷,谢谢你这么做,不可否认,begin-end只是我在学习别人告诉我如果你有一个以上的查询封装它时养成的一个坏习惯。 ( @runid0 as int = 0, @runid1 as i
真的可以在那里做任何事情,只是让它更难阅读。很酷,谢谢你,无可否认,开始-结束只是我在学习别人告诉我的基本上如果你有多个查询封装它时养成的一个坏习惯。是的,这也行得通,但是你不需要有一个表,你可以只选择@arr0,+其他变量..--顺便说一句,begin+end块除了使它更难阅读之外,实际上没有任何作用。很酷,谢谢你这么做,不可否认,begin-end只是我在学习别人告诉我如果你有一个以上的查询封装它时养成的一个坏习惯。
(
@runid0 as int = 0,
@runid1 as int = 0,
@runid2 as int = 0,
@runid3 as int = 0,
@runid4 as int = 0,
@runid5 as int = 0,
@runid6 as int = 0,
@siteid as int
)
AS
declare @effectivedate0 as datetime
declare @effectivedate1 as datetime
declare @effectivedate2 as datetime
declare @effectivedate3 as datetime
declare @effectivedate4 as datetime
declare @effectivedate5 as datetime
declare @effectivedate6 as datetime
set @effectivedate0 = (Select TOP 1 effective_from FROM db_t_run_plan WHERE effective_from <= GetDATE() AND site_id=@siteid AND run_id=@RunID0 order by effective_from DESC)
set @effectivedate1 = (Select TOP 1 effective_from FROM db_t_run_plan WHERE effective_from <= GetDATE() AND site_id=@siteid AND run_id=@RunId1 order by effective_from DESC)
set @effectivedate2 = (Select TOP 1 effective_from FROM db_t_run_plan WHERE effective_from <= GetDATE() AND site_id=@siteid AND run_id=@RunID2 order by effective_from DESC)
set @effectivedate3 = (Select TOP 1 effective_from FROM db_t_run_plan WHERE effective_from <= GetDATE() AND site_id=@siteid AND run_id=@RunID3 order by effective_from DESC)
set @effectivedate4 = (Select TOP 1 effective_from FROM db_t_run_plan WHERE effective_from <= GetDATE() AND site_id=@siteid AND run_id=@RunID4 order by effective_from DESC)
set @effectivedate5 = (Select TOP 1 effective_from FROM db_t_run_plan WHERE effective_from <= GetDATE() AND site_id=@siteid AND run_id=@RunID5 order by effective_from DESC)
set @effectivedate6 = (Select TOP 1 effective_from FROM db_t_run_plan WHERE effective_from <= GetDATE() AND site_id=@siteid AND run_id=@RunID6 order by effective_from DESC)
Select * From
(SELECT arrival as arr0 from db_t_run_orders where run_id = @runid0 and site_id=@siteid and trip_no=1 and visit_order = 1 and effective_from = @effectivedate0) a
Cross Join
(SELECT arrival as arr1 from db_t_run_orders where run_id = @runid1 and site_id=@siteid and trip_no=1 and visit_order = 1 and effective_from = @effectivedate1) b
Cross Join
(SELECT arrival as arr2 from db_t_run_orders where run_id = @runid2 and site_id=@siteid and trip_no=1 and visit_order = 1 and effective_from = @effectivedate2) c
Cross Join
(SELECT arrival as arr3 from db_t_run_orders where run_id = @runid3 and site_id=@siteid and trip_no=1 and visit_order = 1 and effective_from = @effectivedate3) d
Cross Join
(SELECT arrival as arr4 from db_t_run_orders where run_id = @runid4 and site_id=@siteid and trip_no=1 and visit_order = 1 and effective_from = @effectivedate4) e
Cross Join
(SELECT arrival as arr5 from db_t_run_orders where run_id = @runid5 and site_id=@siteid and trip_no=1 and visit_order = 1 and effective_from = @effectivedate5) f
Cross Join
(SELECT arrival as arr6 from db_t_run_orders where run_id = @runid6 and site_id=@siteid and trip_no=1 and visit_order = 1 and effective_from = @effectivedate6) g
RETURN
(
@runid0 as int = 0,
@runid1 as int = 0,
@runid2 as int = 0,
@runid3 as int = 0,
@runid4 as int = 0,
@runid5 as int = 0,
@runid6 as int = 0,
@siteid as int
)
Declare @table Table ( day0 varchar(5), day1 varchar(5), day2 varchar(5), day3 varchar(5), day4 varchar(5), day5 varchar(5), day6 varchar(5))
BEGIN
set @effectivedate0 = (Select TOP 1 effective_from FROM dbo_t_run_plan WHERE effective_from <= GetDATE() AND site_id=@siteid AND run_id=@RunID0 order by effective_from DESC)
set @arr0 = (SELECT arrival as arr from dbo_t_run_orders where run_id = @runid0 and site_id=@siteid and trip_no=1 and visit_order = 1 and effective_from = @effectivedate0)
END
BEGIN
set @effectivedate1 = (Select TOP 1 effective_from FROM dbo_t_run_plan WHERE effective_from <= GetDATE() AND site_id=@siteid AND run_id=@RunId1 order by effective_from DESC)
set @arr1 = (SELECT arrival as arr from dbo_t_run_orders where run_id = @runid1 and site_id=@siteid and trip_no=1 and visit_order = 1 and effective_from = @effectivedate1)
END
BEGIN
set @effectivedate2 = (Select TOP 1 effective_from FROM dbo_t_run_plan WHERE effective_from <= GetDATE() AND site_id=@siteid AND run_id=@RunID2 order by effective_from DESC)
set @arr2 = (SELECT arrival as arr from dbo_t_run_orders where run_id = @runid2 and site_id=@siteid and trip_no=1 and visit_order = 1 and effective_from = @effectivedate2)
END
BEGIN
set @effectivedate3 = (Select TOP 1 effective_from FROM dbo_t_run_plan WHERE effective_from <= GetDATE() AND site_id=@siteid AND run_id=@RunID3 order by effective_from DESC)
set @arr3 = (SELECT arrival as arr from dbo_t_run_orders where run_id = @runid3 and site_id=@siteid and trip_no=1 and visit_order = 1 and effective_from = @effectivedate3)
END
BEGIN
set @effectivedate4 = (Select TOP 1 effective_from FROM dbo_t_run_plan WHERE effective_from <= GetDATE() AND site_id=@siteid AND run_id=@RunID4 order by effective_from DESC)
set @arr4 = (SELECT arrival as arr from dbo_t_run_orders where run_id = @runid4 and site_id=@siteid and trip_no=1 and visit_order = 1 and effective_from = @effectivedate4)
END
BEGIN
set @effectivedate5 = (Select TOP 1 effective_from FROM dbo_t_run_plan WHERE effective_from <= GetDATE() AND site_id=@siteid AND run_id=@RunID5 order by effective_from DESC)
set @arr5 = (SELECT arrival as arr from dbo_t_run_orders where run_id = @runid5 and site_id=@siteid and trip_no=1 and visit_order = 1 and effective_from = @effectivedate5)
END
BEGIN
set @effectivedate6 = (Select TOP 1 effective_from FROM dbo_t_run_plan WHERE effective_from <= GetDATE() AND site_id=@siteid AND run_id=@RunID6 order by effective_from DESC)
set @arr6 = (SELECT arrival as arr from dbo_t_run_orders where run_id = @runid6 and site_id=@siteid and trip_no=1 and visit_order = 1 and effective_from = @effectivedate6)
END
insert into @table values (@arr0,@arr1,@arr2,@arr3,@arr4,@arr5,@arr6)
select * from @table
RETURN