title: Slow running Sql Server query
body: <p>I have the following query:</p>
  
  <pre><code>DECLARE @CompanyId bigint
  DECLARE @SearchText nvarchar(4000)
  SET @CompanyId=160
  SET @SearchText='%02863%'
  SELECT j.Id FROM Job (NOLOCK) j WHERE (j.Deleted = 0 AND j.CompanyId = @CompanyId) 
      AND (j.Name LIKE @SearchText OR j.DisplayId LIKE @SearchText OR j.ClaimNumber LIKE @SearchText) 
  UNION SELECT j.Id FROM Job (NOLOCK) j INNER JOIN Address (NOLOCK) a ON a.Id = j.AddressId 
      WHERE j.Deleted = 0 AND j.CompanyId = @CompanyId 
      AND a.SearchAddress LIKE @SearchText 
  UNION SELECT j.Id FROM Job (NOLOCK) j INNER JOIN Contact (NOLOCK) c ON c.Id = j.CustomerId 
      WHERE j.Deleted = 0 AND j.CompanyId = @CompanyId 
      AND c.SearchName LIKE @SearchText
  </code></pre>
  
  <p>which is taking sometimes upwards of 10 seconds to run.</p>
  
  <p>Our DB is pretty small, and I don't think it should be taking this long, and I'm wondering if I've formulated this query correctly or if I should change it?</p>
  
  <p>From what I've read, I don't believe that implementing full text search would help much since these are direct comparisons, right?</p>
  
  <p>Also, given this query, I'm hoping that it will only search the addresses and contacts that belong to the jobs where companyId=@companyId and deleted=0?  Or will it search all addresses and contacts in the entire DB and then filter based on job criteria?</p>