title: How to give a type to a literal?
body: <p>I would like to tell SQL-Server that a number is of a given type. Here is a little example:</p>
  
  <pre><code>drop table if exists test
  declare @i int = 100000
  
              SELECT 4 pwr, cast(10000 * @i as bigint) val into test    
  insert test SELECT 5,     cast(100000 * @i as bigint)              
  insert test SELECT 6,     cast(1000000 * @i as bigint)
  insert test SELECT 7,     cast(10000000 * @i as bigint)
  insert test SELECT 8,     cast(100000000 * @i as bigint)
  insert test SELECT 9,     cast(1000000000 * @i as bigint)
  insert test SELECT 10,    cast(10000000000 * @i as bigint)
  
  select * from test
  </code></pre>
  
  <p>In the table are only row with pwr 4 and 10. SQL-Server seems to give a numeric literal a datatype depending on the value. High values will be converted into numeric, smaller into int. </p>
  
  <p>Casting to a type is a way to handle this.</p>
  
  <pre><code>insert test SELECT 6, cast(cast(1000000 as bigint) * @i as bigint) test 
  </code></pre>
  
  <p>Is there a way to tell SQL-Server the datatype of a constant other than casting it every time you use it? </p>
  
  <p>Online-Help is unclear here (<a href="https://docs.microsoft.com/en-us/sql/t-sql/data-types/constants-transact-sql" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/sql/t-sql/data-types/constants-transact-sql</a>)
  as it says 'decimal constants are represented by a string of numbers that are not enclosed in quotation marks and contain a decimal point.'. It should say '.. or represented by a numeric value that does not fit into the int range.'</p>