0
実際には複数のユニオンステートメントから異なる値が必要ですが、これは取得できません。 578の複数のユニオン値を持つクエリから異なる値を取得
ここEMP_ID iが一列に必要異なる行の週末や不在を有しています。
私のコードはこのようになります。
select [Employee Name],emp_id,holiDAY,
leave,absent,weekend
from
(
SELECT *FROM
(
select view_emp_info.emp_fullname+' '+'('+''+CONVERT(VARCHAR(50),
(view_emp_info.EMP_ID)) +''+ ')' as [Employee
Name],view_emp_info.emp_id,tbl_emp_forceduty.Holiday_Name as 'HOLIDAY'
,''AS LEAVE,'' AS ABSENT,'' AS [WEEKEND]
from view_emp_Info inner join tbl_emp_forceduty
on view_emp_info.emp_id=tbl_emp_forceduty.emp_id
where
[email protected] and
[email protected] and view_emp_info.emp_id not in
(Select emp_id from tbl_emp_attn_log where [email protected])
and view_emp_info.status_id=1
union
select view_emp_info.emp_fullname+' '+'('+
''+CONVERT(VARCHAR(50),view_emp_info.EMP_ID) +''+ ')' as [Employee
Name],view_emp_info.emp_id,'' AS HOLIDAY
,isnull(tbl_org_leave_log.leavetype,' ') 'LEAVE',
'' AS 'ABSENT',''AS 'WEEKEND'
from view_emp_info inner join tbl_org_leave_log
on view_emp_info.emp_id=tbl_org_leave_log.emp_id
where [email protected] and [email protected]
and view_emp_info.emp_id not in (Select emp_id from tbl_emp_attn_log where
[email protected])
and tbl_org_leave_log.Taken='0.5' and view_emp_info.status_id=1
union
select view_emp_info.emp_fullname+' '+'('+
''+CONVERT(VARCHAR(50),view_emp_info.EMP_ID) +''+ ')' as [Employee
Name],view_emp_info.emp_id,'' AS HOLIDAY ,'' as [LEAVE]
,'' AS 'ABSENT','Weekend'AS 'WEEKEND'
from view_emp_info inner join tbl_org_weekend
on view_emp_info.emp_id=tbl_org_weekend.emp_id or tbl_org_weekend.emp_id=0
where [email protected] and days=datepart(weekday,@date) and
is_weekend=1 and view_emp_info.emp_id not in (Select emp_id from
tbl_emp_attn_log where [email protected])
UNION
select view_emp_info.emp_fullname+' '+'('+
''+CONVERT(VARCHAR(50),view_emp_info.EMP_ID) +''+ ')' as [Employee Name],
view_emp_info.emp_id,'' AS HOLIDAY, '' AS 'LEAVE','Absent' as 'ABSENT',''AS
'WEEKEND'
from view_emp_info inner join tbl_emp_attn_log
on view_emp_info.emp_id!=tbl_emp_attn_log.emp_id
where [email protected] and
view_emp_info.emp_id not in (Select emp_id from tbl_emp_attn_log where
[email protected])
)
T1 where EMP_ID IN (SELECT EMP_ID FROM VIEW_EMP_INFO WHERE
[email protected])
)t2