title: Why does casting text as varchar without specifying a length truncate the text at 30 characters?
body: <p>I was searching an MS-SQL Server 2005 database to make sure that a certain text field was always a multiple of 8 in length.  When I ran the following query, I got that several rows were of length 30.  But when I investigated those records, I found that they were longer than that.</p>
  
  <pre><code>select distinct len(cast(textfield as varchar)) from tablename</code></pre>
  
  <p>However, if I specify the length of the varchar as something longer(as in the following query), it works fine.</p>
  
  <pre><code>select distinct len(cast(textfield as varchar(1000))) from tablename</code></pre>
  
  <p>Anybody know why it defaults to 30 and if this is a configurable setting?</p>