I have a sql server compact framework database and I want to query an int column
the column can contain values from 1 to 99999999 and I am interested in the right 4 digits
Examples:
1 -> 1
12 -> 12
123 -> 123
1234 -> 1234
12345 -> 2345
123456 -> 3456
I could convert the result to string and use substring, but there is propably a better solution.
SQL Server LEN() Function The LEN() function returns the length of a string. Note: Trailing spaces at the end of the string is not included when calculating the length. However, leading spaces at the start of the string is included when calculating the length.
SQL Server LEFT() Function The LEFT() function extracts a number of characters from a string (starting from left).
Use Modulo
select 123456 % 10000
If you
SELECT WhateverField % 10000
you will get the 4 rightmost digits.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With