title: How can I declare a table variable with a decimal variable as the identity seed?
body: <p>I'm using this, but I can't figure out why this doesn't work. SSMS won't give me a useful message other than syntax incorrect:</p>
  
  <pre><code>DECLARE @columnSeed DECIMAL
  SELECT  @columnSeed = MAX([seeded_column]) + 1 FROM [table] (nolock) WHERE [conditions]
  DECLARE @Temp_Table TABLE ([seeded_column] varchar(35) IDENTITY(@columnSeed, 1), [more columns])
  </code></pre>
  
  <p>I want to take the maximum value from a column in one table and create a temporary table variable with an identity column seeded with that previous maximum value.</p>
  
  <p>Edit: OK, after digging around for into about dynamic SQL I think I've got what should work, but it still isn't:</p>
  
  <pre><code>DECLARE @columnSeed DECIMAL
  [@columnSeed set properly]
  EXECUTE sp_executesql 
        N'DECLARE @Temp TABLE (seeded_column decimal IDENTITY(@seed, 1) NOT NULL [more columns])',
        N'@seed decimal',
        @seed = @columnSeed;
  </code></pre>
  
  <p>All the info I get now is that I've incorrect syntax near '@seed'</p>