title: Dynamic Table Insert TSQL
body: <p>Hi all i have been struggling this for a while now! I have some data files with a date in them, these are dumped into a staging table. What i would like my script/function to do is to read the date for each record in the staging table and move to the appropriate table. Now i know i could do this very easily just using some static inserts, for example</p>
  
  <pre><code>INSERT INTO TABLE_2011_08
  WHERE Datafields = 2011_08
  </code></pre>
  
  <p>However i want it to be dynamic, so i was thinking something along the lines of a function/stored procedure to pass in the date for each record. However my brain is melting a bit with this!</p>
  
  <p>The data records in the staging table could be something like this:-</p>
  
  <pre><code>RecordA 2011-08-30 Data Data Data
  RecordB 2011-08-31 Data Data Data
  RecordC 2011-09-01 Data Data Data
  RecordD 2011-09-02 Data Data Data
  </code></pre>