我有一个查询
declare @Leavetype varchar (Max)
select @Leavetype =(select LeaveName from LeaveType)
SELECT *
FROM
( SELECT e.EmpID,
e.EmpName ,
s.LeaveName,
case when l.Approval = 'Approved'
then l.TotalDays
else
0
end AS Total
from EmpInfo e
full JOIN ViewLeave l ON e.EmpID = l.EmpID
LEFT JOIN LeaveType s ON s.LeaveID = l.LeaveID
Where
l.year = '2013'
GROUP BY s.LeaveName,e.EmpID, e.EmpName ,l.Approval,l.TotalDays
)ps
pivot
(
sum(Total)
for LeaveName In ([@LeaveType])
)as pvt
我想从休假类型表中获取动态值Leavetype
LeaveType
表如下
ID Leave type
1 SickLeave
2 Casual Leave
LeaveType
表值可能会有所不同,我必须显示类似的数据
EmpId EmpName SickLeave Casual Leave
101 ramesh 1 0
列数取决于Leavetype
表中的行数
如果有人有想法,请帮助我
此当前查询显示错误
子查询返回超过 1 个值。当子查询跟随 =、!=、<、<=、>、>= 或子查询用作表达式时,这是不允许的。
谢谢