title: Apply IF conditional at the end of the query
body: <p>I'm new in sql server and I have <code>WHERE</code> clause  like this:</p>
  
  <pre><code>WHERE[D].[IsLocked] = 0
  AND(@StartDate IS NULL OR ISNULL([TA].[ModifiedDate], [TA].[CreationDate]) &gt;= @StartDate)
  AND(@EndDate IS NULL OR ISNULL([TA].[ModifiedDate], [TA].[CreationDate]) &lt;= @EndDate)
  AND((CASE WHEN[T].[TaskStatusId] = '09E02513-00AD-49E3-B442-A9ED2833FB25'
    THEN 1 ELSE 0 END) = @Completed)
  AND((@FilterEmpKey IS NULL AND[TA].[EmpKey] = @CurrentEmpKey) 
  OR (ISNULL([TA].[ModifiedAssignedBy], [TA].[AssignatedBy]) = @FilterEmpKey 
  AND[TA].[EmpKey] = @CurrentEmpKey))
  </code></pre>
  
  <p>But now I want to add if conditional in order to add more filters at the end of query like:</p>
  
  <pre><code>  IF(@FilterEmpGuid IS NOT NULL)
      AND[TA].[EmpKey] = @CurrentEmpKey
      AND[TA].[AssignatedBy] = @CurrentEmpKey
      AND[TA].[EmpKey] = @FilterEmpKey
  </code></pre>
  
  <p>But I get:</p>
  
  <blockquote>
    <p>The multi-part identifier  [TA].[EmpKey] could not be bound</p>
  </blockquote>
  
  <p>What am I doing wrong? </p>