title: IF-THEN-ELSE: Create / Truncate Table - SQL Server
body: <p>I am attempting to create a backup table without having to re-create it every single time. If the table already exists in the next run then it should simply truncate the table. </p>
  
  <p>But it doesn't seem to be working. It says <code>backup_reportsettings</code> is already in the database. Can anyone assist me with this?</p>
  
  <pre><code>--Only re-create table if table does not exist otherwise truncate the existing table.   
  IF NOT EXISTS (SELECT * FROM [Misc].sys.tables where name= 'dbo.backup_reportsettings')
      CREATE TABLE [MISC].dbo.backup_reportsettings 
      (
          [datestamp] [datetime] NULL,
          [reportsettingid] [char](8) NOT NULL,
          [description] [char](30) NOT NULL,
          [formname] [char](30) NOT NULL,
          [usersid] [char](8) NOT NULL,
          [settings] [text] NOT NULL,
          [notes] [varchar](255) NOT NULL,
          [userdefault] [char](1) NOT NULL
      )
  ELSE 
      TRUNCATE TABLE [Misc].dbo.backup_reportsettings;
  </code></pre>
  
  <p>What am I doing wrong? Note: this is done within a transaction.</p>