title: Check Excel file destination temp table in SSIS?
body: <p>I have created ssis package to generate excel file dynamically from sql table.</p>
  
  <p>But when I try to check whether that excel connection temp table if present or not using below query in sql task it gets failed syntax error</p>
  
  <pre><code>IF object_id(MyExcel) is not null
  
  CREATE TABLE `MyExcel` (
      `CUSIP` varchar(50),
      `FaceAmount` decimal(18,4),
      `Portfolio` varchar(50),
      `PositionDate` DateTime,
      `PositionCost` decimal(18,6),
      `CurrentPrice` decimal(18,6)
  )
  
  else drop table MyExcel
  </code></pre>
  
  <p>ERROR :</p>
  
  <pre><code>[Execute SQL Task] Error: Executing the query "IF object_id(MyExcel) is not null
  
  CREATE TABLE `..." failed with the following error: "Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
  </code></pre>
  
  <p>Please advise? </p>
  
  <p>I have tried with answer</p>
  
  <pre><code>IF OBJECT_ID(N'MyExcel') IS NOT NULL
      BEGIN
          DROP TABLE MyExcel;
      END;
  
  CREATE TABLE [MyExcel] 
  (
      [CUSIP]         VARCHAR(50),
      [FaceAmount]    DECIMAL(18,4),
      [Portfolio]     VARCHAR(50),
      [PositionDate]  DATETIME,
      [PositionCost]  DECIMAL(18,6),
      [CurrentPrice]  DECIMAL(18,6)
  );
  </code></pre>
  
  <p>But still getting same error for statements </p>
  
  <pre><code> IF OBJECT_ID(N'MyExcel') IS NOT NULL
          BEGIN
              DROP TABLE MyExcel;
          END;
  </code></pre>
  
  <p>I'm using this query inside <code>SQL TASK</code> 
  Connection type is <code>EXCEL</code>
  <img src="https://i.stack.imgur.com/9kab9.png" alt="enter image description here"></p>