title: SQL Server:An expression of non-boolean type specified in a context where a condition is expected
body: <p>I apologize I'm asking this question when this specific error type has already been asked multiple times before, but I've looked through them and am not explicitly seeing my answer.</p>
  
  <p>I am trying to build a trigger that takes records inserted into a table (FDC_Trip_History), selects some information from the record, joins on other tables to pull additional data, etc. and inserts a record into another table (Staging).</p>
  
  <p>I'm getting this error at the bottom of my script, the 4th line from the end after the FROM section.   Any idea why?</p>
  
  <pre><code>CREATE TRIGGER Insert_Trip_History ON FDC_Trip_History
  AFTER INSERT
  AS BEGIN
  
  SET NOCOUNT ON;
      --If inserted record reaches a certain 'status' of archive then continue
      If EXISTS (SELECT * FROM inserted WHERE inserted.description like '%archive%')
  
      BEGIN
          --If inserted record can be 'billed', and hasn't already been processed, then continue.
          IF EXISTS (    SELECT * FROM inserted 
                      INNER JOIN FDC_Trips on inserted.tdate = FDC_Trips.tdate and inserted.job = FDC_Trips.job and inserted.SourceDB = FDC_trips.sourceDB
                      INNER JOIN AMS.dbo.Billable_Outcome_Filter as eBill on FDC_trips.SourceDB = eBill.SourceDB and FDC_Trips.outcome = eBill.Outcome_Code)
          AND NOT EXISTS (     SELECT * FROM inserted
                              INNER JOIN Staging as Stg on inserted.tdate = Stg.tdate and inserted.job = Stg.job and inserted.sourcedb = Stg.sourceDB)
              BEGIN    
                  INSERT INTO Staging
                      (EVENT_OPERATION,
                      EVENT_SOURCE_TABLE,
                      EVENT_PRIORITY,
                      EVENT_TIME_UPDATED,
                      EVENT_STATUS,
                      EVENT_COMMENT,
                      TDATE,
                      JOB,
                      SOURCEDB,
                      CUSTNO,
                      SHIFTNO,
                      TYPE,
                      PROFITCENTER,
                      BILLINGRATEPROFITCENTER)                
                  SELECT 
                      'CREATE' as [EVENT_OPERATION],
                      'FDC_Trip_History' as [EVENT_SOURCE_TABLE],
                      '1' as [EVENT_PRIORITY],
                      GETDATE() as [EVENT_TIME_ADDED],
                      null as [EVENT_TIME_UPDATED],
                      '0' as [EVENT_STATUS],
                      ''  as [EVENT_COMMENT],
                      eTHistory.tdate as [TDATE],
                      eTHistory.job as [JOB],
                      eTHistory.sourcedb as [SOURCEDB],
                      eT.custno as [CUSTNO],
                      eT.shiftno as [SHIFTNO],
                      'Completed' as [TYPE],
                      --Decide Profit Center.  Profit center (PC) determined from dispatch zone (Trips.dzone)
                      CASE 
                          WHEN cType.descr LIKE 'ATS%'
                              THEN DispatchZone.ATS_ProfitCenter
                          ELSE DispatchZone.ProfitCenter
                      END,
                      --Decide Billing rate profit center.  Billing rate profit center (BRPC) determined from pickup zone.  Does ATS logic apply to BRPC too?
                      CASE
                          WHEN cType.descr LIKE 'ATS%'
                              THEN PickupZone.ATS_ProfitCenter
                          ELSE PickupZone.ProfitCenter
                      END
                       as [BILLINGRATEPROFITCENTER]
                      FROM inserted
                          INNER JOIN FDC_Trip_History as eTHistory
                          INNER JOIN FDC_Trips as eT on eTHistory.tdate = eT.tdate and eTHistory.job = eT.job and eTHistory.sourcedb = eT.sourcedb
                          LEFT JOIN Trips as T on T.tdate = eTHistory.tdate and T.sourcedb = eTHistory.sourceDB and T.Job = eTHistory.Job
                          LEFT JOIN Call_Types as cType on cType.code = eT.calltype and cType.sourceDB = eT.sourceDB
                          LEFT JOIN Zones as DispatchZone on DispatchZone.code = T.dzone
                          LEFT JOIN Zones as PickupZone on PickupZone.code = eT.puzone /* Error pops up right here */
              END
      END
  END
  </code></pre>