我有這樣的查詢:過濾器的SQL查詢的SQL Server
SELECT
tbl.EmpID,
CASE
WHEN emp.status = 'terminated' THEN CONVERT(bit, 1)
ELSE CONVERT(bit, 0)
END AS 'Status',
CASE
WHEN tbl.LeaveTypeId = 'a' THEN CONVERT(bit, 1)
ELSE CONVERT(bit, 0)
END AS 'Absent',
CASE
WHEN (tbl.outime IS NULL) AND
(tbl.LeaveTypeId <> 'a' and tbl.LeaveTypeId Is null) THEN CONVERT(bit, 1)
ELSE CONVERT(bit, 0)
END AS 'InOut',
emp.EmpFullName,
tbl.P_Date,
cmp.cmplogo,
emp.nation_id,
emp.dept_id,
emp.desig_id AS 'designation_id',
emp.tradecd,
emp.comp_id,
emp.section_id,
emp.location_id,
emp.emplcatgry
FROM tblattendance tbl
INNER JOIN EMPLOYEEs emp
ON emp.empid = tbl.empid
INNER JOIN Company cmp
ON cmp.comp_id = emp.comp_id
WHERE CONVERT(varchar(10), tbl.p_date, 112) BETWEEN '20160901' AND '20160902'
我出來就把未來類似這樣的
empid status absent inout
121 1 1 1
122 0 0 0
但只有我想用狀態造成的,不存在,inout大於0,所以我怎麼寫條件。
不知道是什麼用意,但這樣的:'(tbl.LeaveTypeId <> 'a' 和tbl.LeaveTypeId爲空)'沒有任何意義,因爲如果它是NULL,它永遠不能與chars比較。應該是OR而不是AND? – Beth