我有两个表,employee
和employee time entry
。我运行了一个查询,向我显示输入时间总和或0为空值的所有员工。在下一栏我有周数。如果员工在一周内没有输入时间而不是给我0,但它也在周数给我空值。如果员工没有输入,我怎么强制查询才能显示周数。
Select
Concat(Empfname,Emplname) as EmployeeName,
department,
iif (sum(whours) is null, 0, sum(whours)) CurrentHours,
Datepart (ww,wdate) WeekNum
From
employee as e
left outer join
TimeEntry as w on e.id = w.eId
and wdate between '01/01/2017' and '01/31/2017'
group by
Concat(Empfname,Emplname), department, Datepart(ww, wdate)
输出
EmployeeName Department CurrentHours WeekNum
------------------------------------------------
John Smith Sales 8 1
Smith John Operations 0 Null
我怎么能告诉它也来自WeekNum 1?
由于
答案 0 :(得分:1)
我们的想法是使用int i = 0;
dataArray[i];
i++;
生成所有行,然后使用cross join
引入您想要的行:
left join
答案 1 :(得分:0)
试试这个:
Select Concat(Empfname,Emplname) as EmployeeName, department
iif (sum(whours) is null, 0, sum(whours)) CurrentHours
ISNULL(Datepart (ww,wdate),1) WeekNum
From employee as e left outer join TimeEntry as w on e.id=w.eId
and wdate between '01/01/2017' and '01/31/2017'
group by Concat(Empfname,Emplname), department, ISNULL(Datepart (ww,wdate),1)
会强制任何NULL
值显示1
而不是NULL
本身