SQL Server - Error converting data type nvarchar to bigint
<p>When I run following query with <code>SELECT *</code> I get error saying :</p>

<blockquote>
  <p>[S0005][8114] Error converting data type nvarchar to bigint.</p>
</blockquote>

<pre><code>SELECT * FROM (
                SELECT * , ROW_NUMBER() OVER (ORDER BY CAST(id as BIGINT)) AS RowNum
                FROM users
            ) AS users
            WHERE users.RowNum BETWEEN 0 AND 5 ;
</code></pre>

<p>When I run this query only with <code>SELECT id , ROW_NUMBER() ...</code> everything works.</p>

<p>My DB looks like this:</p>

<p><img src="https://i.stack.imgur.com/SPHpy.png" alt="Image of database"></p>

<p>This query run well with other table where <code>id</code> column is <code>NVARCHAR</code></p>

<p>ID column is number only and if i cast it as : CAST(id as NVARCHAR) i get same error.</p>

<p>EDIT:</p>

<p>I Found problem with column ID values</p>

<p>ID 46903836
ID 9100000004</p>

<p>Small ids dont have leading zeros</p>