Мне нужно заполнить таблицу Rota для драйверов из документа excel, где хранятся номера идентификаторов поездки.Извлечение нескольких, но не всех полей, но одного столбца
на загрузку в приложение, мне нужно это, чтобы принести время начала этого запуска из таблицы выполняется в течение каждого дня с помощью SP
Эта часть не является проблемой, и все прекрасно работает проблема начинается тогда, когда определенные дни являются «0» (выходной день), поэтому, если драйвер не используется для ежедневной недели, данные не возвращаются.
Я знаю, что это не очень привлекательный SQL, но это просто быстрый макет, чтобы объяснить проблему.
Вот T-SQL
(
@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 [email protected] AND [email protected] order by effective_from DESC)
set @effectivedate1 = (Select TOP 1 effective_from FROM db_t_run_plan WHERE effective_from <= GetDATE() AND [email protected] AND [email protected] order by effective_from DESC)
set @effectivedate2 = (Select TOP 1 effective_from FROM db_t_run_plan WHERE effective_from <= GetDATE() AND [email protected] AND [email protected] order by effective_from DESC)
set @effectivedate3 = (Select TOP 1 effective_from FROM db_t_run_plan WHERE effective_from <= GetDATE() AND [email protected] AND [email protected] order by effective_from DESC)
set @effectivedate4 = (Select TOP 1 effective_from FROM db_t_run_plan WHERE effective_from <= GetDATE() AND [email protected] AND [email protected] order by effective_from DESC)
set @effectivedate5 = (Select TOP 1 effective_from FROM db_t_run_plan WHERE effective_from <= GetDATE() AND [email protected] AND [email protected] order by effective_from DESC)
set @effectivedate6 = (Select TOP 1 effective_from FROM db_t_run_plan WHERE effective_from <= GetDATE() AND [email protected] AND [email protected] order by effective_from DESC)
Select * From
(SELECT arrival as arr0 from db_t_run_orders where run_id = @runid0 and [email protected] 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 [email protected] 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 [email protected] 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 [email protected] 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 [email protected] 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 [email protected] 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 [email protected] and trip_no=1 and visit_order = 1 and effective_from = @effectivedate6) g
RETURN
Это просто возвращается 1 строку с 7 столбцов, одно значение для каждого из @runids и результат 0 строк, потому что один из наборов результатов пуст? Не могли бы вы изменить шаблон пересечения, чтобы объединить все, а затем повернуть результат в столбцы? –
Привет, да 1 строка с 7 столбцами - это то, что им нужно, но если runid равен 0, тогда мне нужна эта колонка, чтобы быть пустой, например, дни солнца, чтобы работать на работе '--- 0 ------ 1-- ------ 2 ------ 3 -------- 4 -------- 5 ------- 6 - ' ' 10:00 12:00 10:00 10:00 - - - ' никогда не использовал функцию поворота, прежде чем я немного поработаю и вернусь к вам – user3652973