Задавайте вопросы, мы ответим
Вы не зашли.
есть запрос
SELECT
ID,
ServTime,
Date AS ServDate,
[Quantity],
[Additional],
EmployeeInBranch_Employee,
Code,
Client,
TimeBegin,
TimeEnd,
Comment,
ClientsSimultaneously,
NonAppeared,
Vacation,
Commercial
FROM
((SELECT
ID,
ServDateTime,
ServTime,
ServDate,
Served_Employee,
[Quantity],
[Additional],
Code,
Client,
Comment,
NonAppeared,
Commercial = 0
FROM
Served
WHERE
(
Served.ServDateTime >= @DateFrom
AND
Served.ServDateTime < @DateTo
)
)
UNION ALL
(SELECT
ID,
ServDateTime,
ServTime,
ServDate,
Served_Employee,
[Quantity],
Additional = 0,
Code,
Client,
Comment = null,
NonAppeared = 0,
Commercial = 1
FROM
CommServed
WHERE
(
ServDate >= @DateFrom
AND
ServDate < @DateTo
)
)) as Served
RIGHT JOIN
(
SELECT
CONVERT(TIME, [TimeBegin]) AS TimeBegin,
CONVERT(TIME, TimeEnd) AS TimeEnd,
Date,
[ClientsSimultaneously],
EmployeeInBranch_Employee,
(CASE
WHEN Date BETWEEN EmployeeInBranchSet.Vacation1From AND EmployeeInBranchSet.Vacation1To THEN 1
WHEN Date BETWEEN EmployeeInBranchSet.Vacation2From AND EmployeeInBranchSet.Vacation2To THEN 1
WHEN Date BETWEEN EmployeeInBranchSet.Vacation3From AND EmployeeInBranchSet.Vacation3To THEN 1
ELSE 0
END) AS Vacation
FROM
[OCRI].[dbo].[TimeTableSet]
LEFT JOIN EmployeeInBranchSet
ON (EmployeeInBranchSet.Id=TimeTable_EmployeeInBranch)
CROSS JOIN
(
SELECT
TOP (DATEDIFF(DAY, @DateFrom, DATEADD(DAY, -1, @DateTo)) + 1)
Date = DATEADD(DAY, ROW_NUMBER() OVER(ORDER BY a.object_id) - 1, @DateFrom)
FROM
sys.all_objects a
CROSS JOIN
sys.all_objects b
)
as Dates
WHERE EmployeeInBranch_Branch = @Branch
)
as TimeTable
ON
(
Served_Employee = EmployeeInBranch_Employee
AND
ServTime >= TimeBegin
AND
ServTime < TimeEnd
AND
ServDate = Date
AND
(ServDate BETWEEN @DateFrom AND @DateTo
OR
ServDate IS NULL)
)
Как в нем сделать чтобы два определенных расписания связать
Неактивен
никак не могу дотукать
Неактивен