I want to retrieve the left 3 numbers from an integer to be stored in a table. For example, if the int is 1234567, I want to retrieve 123. I want the second number (123) to also be an int; I don’t want to convert anything to a string.
(And yes, really I should be working with strings. But I don’t have control over that aspect of the issue.)
Thank you!
For SQL Server, the easiest way would definitely be:
Convert to string, take the left most three characters, and convert those back to an INT.
Doing it purely on the numerical value gets messy since you need to know how many digits you need to get rid of and so forth…
If you want to use purely only INT’s, you’d have to construct something like this (at least you could do this in SQL Server – I’m not familiar enough with Access to know if that’ll work in the Access SQL “dialect”):
But that’s always an approximation – what if you have a really really really large number….. it might just fall through the cracks….