我有兩個表,employee
和employee time entry
。我運行了一個查詢,向我顯示所有員工輸入的時間總和或0作爲空值。在下一列中我有周編號。如果員工在一週內沒有輸入時間,那麼它在給予我0的時候也沒有輸入時間,但是它也在我的週數中給出了空值。假設沒有員工進入,我怎麼能強制查詢顯示我的週數。SQL根據查詢顯示空值的日期
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?
感謝
如果員工沒有及時進入,您怎麼知道它屬於第1周? – GurV
如果沒有參賽作品,您希望顯示幾周的數字? – Mureinik
你可以使用'coalesce(Datepart(ww,wdate),1)',如果你希望它成爲1,那麼它會變爲null – GurV