Is there a function like SUBSTRING but for integers?

I'm wondering if there is a function in SQL that works like SUBSTRING function but for integers. Like for example if I have a number like 20010112 and I want to cut it to the first for digits so that it reads 2001


Answer this question

Is there a function like SUBSTRING but for integers?

  • FunkeyMonkey

    You use LEFT function.

    SELECT LEFT(20010112, 4)

    You should get 2001

    This function works on string too.


  • losoriomx

    this left function is for string. if you pass in a integer, the integer value is implicit convert to string
    so 20010112 is converted to '20010112'.

    You can convert the integer to string before using substring

    substring(convert(varchar(10), @intvar), 5, 2)


  • Is there a function like SUBSTRING but for integers?