For SQL Server, the easiest way :
SELECT CAST(LEFT(CAST(YourInt AS VARCHAR(100)), 3) AS INT)
Convert to a string, take the left most three characters and convert them back to INT.
Doing this purely on a numerical value becomes messy as you need to know how many digits you need to get rid of, etc ...
If you want to use only INT only, you will need to build something like this (at least you can do it in SQL Server - I'm not knowledgeable enough about Access to find out if this works in Access SQL "dialect") :
DECLARE @MyInt INT = 1234567 SELECT CASE WHEN @MyInt < 1000 THEN @MyInt WHEN @MyInt > 10000000 THEN @MyInt / 100000 WHEN @MyInt > 1000000 THEN @MyInt / 10000 WHEN @MyInt > 100000 THEN @MyInt / 1000 WHEN @MyInt > 10000 THEN @MyInt / 100 WHEN @MyInt > 1000 THEN @MyInt / 10 END AS 'NewInt'
But this is always an approximation - what if you really have a really really large quantity ..... it can just fall through the cracks ....
marc_s
source share