title: Create a table using a variable as the table name
body: <p>I need to create a table where the name will be the value of 4 variables and some string.  </p>
  
  <p>I've found various questions/answers, but nothing that really matches what I'm after.  Ultimately this will be used as embedded SQL on an eForm, but for the time being I'm trying to achieve this directly in MS SQL Server Management Studio.  </p>
  
  <p>This is what I have:</p>
  
  <pre><code>DECLARE @INSFIRSTNAME VARCHAR (100) = 'Ted'
  DECLARE @INSSURNAME VARCHAR (100) = 'Smith'
  DECLARE @INSSTAFFNO VARCHAR (10) = 'AB123'
  DECLARE @INSYEAR VARCHAR (10) = '2018'
  DECLARE @TABLENAME VARCHAR (400) = 'Timesheet_' + @INSFIRSTNAME + @INSSURNAME + @INSSTAFFNO + '_' + @INSYEAR
  
  CREATE TABLE @TABLENAME
               (INSFIRSTNAME VARCHAR (100),
                INSSURNAME VARCHAR (100),
                INSSTAFFNO VARCHAR (10),
                INSYEAR VARCHAR (10));
  INSERT INTO   @TABLENAME
                (INSFIRSTNAME, INSSURNAME, INSSTAFFNO, INSYEAR)
  VALUES        (@INSFIRSTNAME, @INSSURNAME, @INSSTAFFNO, @INSYEAR)
  </code></pre>
  
  <p>This throws up the message:</p>
  
  <blockquote>
    <p>"Incorrect syntax near '@TABLENAME'.</p>
  </blockquote>
  
  <p>I've tried various ways of populating the TABLENAME variable, but nothing has worked.  From what I've read dynamic SQL appears to be the answer, but I haven't found a way to achieve this.  Any help will be very much appreciated.</p>