0

好的,问题来了

   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.DRUGSCREENINGREQUIREDandCONT.BACKGROUNDCHECKREQUIRED为真时,我只想用TECH.PASSEDDRUGTESTand过滤记录TECH.PASSEDBACKGROUNGCHECKTECH.PASSEDDRUGTEST如果它们不是真的,我想要所有记录,无论TECH.PASSEDBACKGROUNGCHECK是真还是假。

4

2 回答 2

0

也许我误解了这个问题,但你能不能不这样做?

WHERE CONT.DRUGSCREENINGREQUIRED = 'FALSE' OR CONT.DRUGSCREENINGREQUIRED = 'TRUE' AND TECH.PASSEDDRUGTEST = 'TRUE'
于 2012-08-16T10:48:07.063 回答
0

如果这些标志是独立的(与问题相反,但在我看来应该如此),您可能会检索不需要检查或通过检查的记录,简而言之如下:

WHERE (CONT.DRUGSCREENINGREQUIRED = 'FALSE' OR TECH.PASSEDDRUGTEST = 'TRUE')
  AND (CONT.BACKGROUNDCHECKREQUIRED = 'FALSE' OR TECH.PASSEDBACKGROUNGCHECK = 'TRUE')

如果你真的想检查passed两个标志是否都被提升了,那么你可以使用这个模式:

WHERE (    CONT.DRUGSCREENINGREQUIRED = 'FALSE' 
        OR CONT.BACKGROUNDCHECKREQUIRED = 'FALSE'
        OR (     TECH.PASSEDDRUGTEST = 'TRUE' 
             AND TECH.PASSEDBACKGROUNGCHECK = 'TRUE'
           )
      )
于 2012-08-16T11:48:38.400 回答