Last active
June 17, 2019 10:25
-
-
Save dmlogv/40a17e89053a12ebb178e0185b266eab to your computer and use it in GitHub Desktop.
Random integer number in Transact-SQL (Microsoft SQL Server)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Slow method | |
Pre-use my integer's table: https://gist.github.com/dm-logv/38eb66f5a2a461cb8f42e14714682daa | |
*/ | |
SELECT TOP 1 i | |
FROM #integers | |
ORDER BY NEWID(); | |
/* | |
Mid-fast method | |
Range [0; @max) | |
*/ | |
DECLARE @max INT = 1000000; | |
SELECT ABS(CHECKSUM(NEWID())) % @max; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment