好的,问题来了
SELECT CTE.TECHNICIANID, SUM(TLEVEL) AS TLEVEL, TECH.PASSEDDRUGTEST, TECH.PASSEDBACKGROUNGCHECK, TECH.FIRSTNAME, TECH.LASTNAME,
CM.CITYID, CM.ADDRESS, CM.EMAIL, CM.PHONENUMBER, CM.ZIPCODE, CNTRY.COUNTRYNAME, SM.STATENAME,
CM.LATITUDE, CM.LONGITUDE FROM CTE
INNER JOIN TECHNICIAN TECH ON CTE.TECHNICIANID = TECH.TECHNICIANID
INNER JOIN SERVICEORDER SO ON SO.SERVICEORDERID = @SERVICEORDERID
INNER JOIN CONTRACT CONT ON SO.CONTRACTID = CONT.CONTRACTID
INNER JOIN CONTACTMASTER CM ON CM.CONTACTID = TECH.CONTACTID
INNER JOIN COUNTRYMASTER CNTRY ON CM.COUNTRYID = CNTRY.COUNTRYID
INNER JOIN STATEMASTER SM ON SM.STATEID = CM.STATEID
--WHERE CONT.DRUGSCREENINGREQUIRED = CASE CONT.DRUGSCREENINGREQUIRED WHEN 'TRUE' THEN TECH.PASSEDDRUGTEST END AND
--CONT.BACKGROUNDCHECKREQUIRED = CASE CONT.BACKGROUNDCHECKREQUIRED WHEN 'TRUE' THEN TECH.PASSEDBACKGROUNGCHECK END
GROUP BY CTE.TECHNICIANID, TECH.PASSEDDRUGTEST, TECH.PASSEDBACKGROUNGCHECK,CM.LATITUDE, TECH.FIRSTNAME, TECH.LASTNAME,
CM.CITYID, CM.ADDRESS, CM.EMAIL, CM.PHONENUMBER, CM.ZIPCODE, CNTRY.COUNTRYNAME, SM.STATENAME, CM.LONGITUDE ORDER BY TLEVEL DESC
使用 where 子句查看查询中的注释部分,我想要的是在drugscreening
需要时true
我想要所有记录,passeddrugtest
否则true
我不想应用任何条件
编辑:当CONT.DRUGSCREENINGREQUIRED
andCONT.BACKGROUNDCHECKREQUIRED
为真时,我只想用TECH.PASSEDDRUGTEST
and过滤记录TECH.PASSEDBACKGROUNGCHECK
。TECH.PASSEDDRUGTEST
如果它们不是真的,我想要所有记录,无论TECH.PASSEDBACKGROUNGCHECK
是真还是假。