title: Create Table Variable only when there is rows to insert in it
body: <p>In Query that haves 3 tables variables joined with 2 tables in some cases where those variable tables are empty (no rows) in the Execution Plan still appears with 16% cost for the scan of each table variable.</p>
  
  <p>From searching found this rule </p>
  
  <blockquote>
    <p>If a table variable is joined with other tables in SQL Server, it may
    result in slow performance due to inefficient query plan selection
    because SQL Server does not support statistics or track number of rows
    in a table variable while compiling a query plan</p>
  </blockquote>
  
  <p>from <a href="https://sqlperformance.com/2014/06/t-sql-queries/table-variable-perf-fix" rel="nofollow noreferrer">https://sqlperformance.com/2014/06/t-sql-queries/table-variable-perf-fix</a></p>
  
  <p>So my question is it worth it before creating the table variable and inserting rows into it, validate if there is any rows to insert in the first place and ignore the creation of the table variable and in the query where have 3 variable table ignore the joins for table variable that weren't created?</p>