高级SQL查询,需要添加另一个表和员工ID
我是高级SQL的新手。我有一个需要添加变量的查询。它需要连接到employee表,并且只显示该特定employeeId的记录。这是Outsystems和高级SQL查询。有什么想法吗 这就是我需要添加的:Employee.EmployeeId=EmployeeId或EmployeeId=NullIdentifier 我需要将以上内容添加到一些how中的现有查询:高级SQL查询,需要添加另一个表和员工ID,sql,join,inner-join,outer-join,outsystems,Sql,Join,Inner Join,Outer Join,Outsystems,我是高级SQL的新手。我有一个需要添加变量的查询。它需要连接到employee表,并且只显示该特定employeeId的记录。这是Outsystems和高级SQL查询。有什么想法吗 这就是我需要添加的:Employee.EmployeeId=EmployeeId或EmployeeId=NullIdentifier 我需要将以上内容添加到一些how中的现有查询: Select EMPLOYEEDISPLAYNAME , ISNULL(Sick.Total,0.00) as
Select
EMPLOYEEDISPLAYNAME ,
ISNULL(Sick.Total,0.00) as SickValue,
ISNULL( Vacation.Total,0.00) as VacationValue
from
{Employee}
left join
( Select
EMPLOYEEID,
Sum( DEPOSITVALUE ) - Sum( WITHDRAWLVALUE ) as Total
from
{TimeOffRegisterEntry}
join {TimeOffRegister}
on {TimeOffRegisterEntry}.TimeOffRegisterId = {TimeOffRegister}.TimeOffRegisterId
join {TimeOffYear}
on {TimeOffRegister}.TimeOffYearId = {TimeOffYear}.TimeOffYearId
where
TIMEOFFTYPE = @VacationType
and {TimeOffYear}.[TimeOffYearId] = @Year
group by
EMPLOYEEID
having
Sum( DEPOSITVALUE ) - Sum( WITHDRAWLVALUE ) < 0
) as Vacation
on {Employee}.EmployeeId = Vacation.EMPLOYEEID
left join
( Select
EMPLOYEEID,
Sum( DEPOSITVALUE ) - Sum( WITHDRAWLVALUE ) as Total
from
{TimeOffRegisterEntry}
join {TimeOffRegister}
on {TimeOffRegister}.TimeOffRegisterId = {TimeOffRegisterEntry}.TimeOffRegisterId
join {TimeOffYear}
on {TimeOffRegister}.TimeOffYearId = {TimeOffYear}.TimeOffYearId
where
TIMEOFFTYPE = @SickType
and {TimeOffYear}.[TimeOffYearId] = @Year
group by
EMPLOYEEID
having
Sum( DEPOSITVALUE ) - Sum( WITHDRAWLVALUE ) < 0
) as Sick
on {Employee}.EmployeeId = Sick.EMPLOYEEID
where
Vacation.total is not null
or Sick.Total is not null
我认为您应该看看这里建议的机制,传入一个输入变量并设置“expand”:
Outsystems论坛是一种知识的载体!他们的功劳 您需要向查询EmployeeId添加一个新参数,可能是EmployeeId Identifier类型,并将该条件添加到查询中 在不了解完整数据库结构的情况下: 仅在条件足够的最外层添加它 可能还需要将其添加到内部查询中/优化查询 最后,查询看起来像
Select
EMPLOYEEDISPLAYNAME ,
ISNULL(Sick.Total,0.00) as SickValue,
ISNULL( Vacation.Total,0.00) as VacationValue
from
{Employee}
left join
( Select
EMPLOYEEID,
Sum( DEPOSITVALUE ) - Sum( WITHDRAWLVALUE ) as Total
from
{TimeOffRegisterEntry}
join {TimeOffRegister}
on {TimeOffRegisterEntry}.TimeOffRegisterId = {TimeOffRegister}.TimeOffRegisterId
join {TimeOffYear}
on {TimeOffRegister}.TimeOffYearId = {TimeOffYear}.TimeOffYearId
where
TIMEOFFTYPE = @VacationType
and {TimeOffYear}.[TimeOffYearId] = @Year
AND (@EmployeeId = 0 OR EMPLOYEEID = @EmployeeId)
group by
EMPLOYEEID
having
Sum( DEPOSITVALUE ) - Sum( WITHDRAWLVALUE ) < 0
) as Vacation
on {Employee}.EmployeeId = Vacation.EMPLOYEEID
left join
( Select
EMPLOYEEID,
Sum( DEPOSITVALUE ) - Sum( WITHDRAWLVALUE ) as Total
from
{TimeOffRegisterEntry}
join {TimeOffRegister}
on {TimeOffRegister}.TimeOffRegisterId = {TimeOffRegisterEntry}.TimeOffRegisterId
join {TimeOffYear}
on {TimeOffRegister}.TimeOffYearId = {TimeOffYear}.TimeOffYearId
where
TIMEOFFTYPE = @SickType
and {TimeOffYear}.[TimeOffYearId] = @Year
AND (@EmployeeId = 0 OR EMPLOYEEID = @EmployeeId)
group by
EMPLOYEEID
having
Sum( DEPOSITVALUE ) - Sum( WITHDRAWLVALUE ) < 0
) as Sick
on {Employee}.EmployeeId = Sick.EMPLOYEEID
where
(@EmployeeId = 0 OR {Employee}.[EmployeeId] = @EmployeeId)
AND (
Vacation.total is not null
or Sick.Total is not null
)
在上述代码段中查找对@EmployeeId的引用
请注意和。。。或包装备用条件哪个dbms?那里有些非ANSI SQL。。。另外,您是否可以尝试格式化查询,以便无需太多努力即可读取?