title: Define varchar with variable length
body: <p>I am attempting to modify the datatype of a specific column in a specific table in a SQL Server 2012 database. in the beginning of the script, the user will be setting the new desired length of the column datatype. However when I attempt to alter the column in the table to set the new <code>varchar</code> length I am getting an error. </p>
  
  <p>Here is the code snippet and the resulting error:</p>
  
  <pre><code>Declare @newPrecis int
  
  Set @newPrecis = 23 -- New length of the index
  
  Alter Table [dbo].[VTAB0047] Alter Column VAL varchar(@newPrecis)
  </code></pre>
  
  <p>Error:    </p>
  
  <blockquote>
    <p>Msg 102, Level 15, State 1, Line 5<br>
    Incorrect syntax near '@newPrecis'.</p>
  </blockquote>
  
  <p>Currently the length of the <code>VAL</code> column is <code>varchar(20)</code> and I'd like it to be set to a length of 23 or whatever length is inputted in the <code>set</code> statement. </p>
  
  <p>I'm ignoring any type of error checking at the moment because I'm simply trying to get the basic functionality down.</p>