Specify string length for substring length parameter in T-SQL
<p>According to this <a href="https://msdn.microsoft.com/en-gb/library/ms187748(v=sql.100).aspx" rel="nofollow">msdn</a> article and using the Substring:</p>

<p><code>SUBSTRING (value_expression ,start_expression ,length_expression )</code></p>

<blockquote>
  <p><em>length_expression</em></p>
  
  <p>Is a positive integer or bigint expression that specifies how many
  characters of the value_expression will be returned. If
  length_expression is negative, an error is generated and the statement
  is terminated. <strong>If the sum of start_expression and length_expression is
  greater than the number of characters in value_expression, the whole
  value expression beginning at start_expression is returned.</strong></p>
</blockquote>

<p>So if I had:</p>

<pre><code>DECLARE @data varchar(max)

SELECT TOP 1 @data = Data
    FROM [SomeDatabase].[dbo].[MyTable]

SELECT SUBSTRING(@data, 10, LEN(@data))
</code></pre>

<p>My understanding that because <code>SUBSTRING</code> has found that the length asked for is longer than the length of string supplied it will return you everything from the <em>start_index</em> till then end of the string will be taken.</p>

<p>for example if:</p>

<pre><code>@data = "hey there"; // char length of 9
SUBSTRING(@data, 4, 20)
</code></pre>

<p>This should return <code>there</code></p>

<p>Is this a particularly bad thing to do? </p>

<p>Are there any caveats to doing this?</p>

<p>Should I be explicit about the length of string to return?</p>