Last active
August 29, 2015 14:07
-
-
Save peschkaj/cebdeb98daa4d1f08dc5 to your computer and use it in GitHub Desktop.
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
WITH rando | |
AS ( SELECT 1 + ABS(CHECKSUM(NEWID())) % ( 4 ) AS RandomNumber | |
FROM master.dbo.spt_values sv | |
WHERE sv.type = 'P' | |
AND sv.number < 4 | |
) | |
SELECT r.RandomNumber , | |
d.number | |
FROM rando AS r | |
INNER JOIN master.dbo.spt_values d ON r.RandomNumber = d.number | |
WHERE d.type = 'P' |
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
WITH rando | |
AS ( SELECT TOP 4 1 + ABS(CHECKSUM(number)) % ( 4 ) AS RandomNumber | |
FROM master.dbo.spt_values sv | |
--WHERE sv.type = 'P' | |
ORDER BY NEWID() | |
) | |
SELECT r.RandomNumber , | |
d.number | |
FROM rando AS r | |
INNER JOIN master.dbo.spt_values d ON r.RandomNumber = d.number | |
WHERE d.type = 'P' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment