Sample Data
DECLARE @RandomNumber TABLE(Col1 int)
INSERT INTO @RandomNumber VALUES (102),(523),(413),(9),(126),(83091),(36)
|
Query
DECLARE @n INT = 3
SELECT
*
, AssignedNumber = (ROW_NUMBER() OVER (ORDER BY Col1) - 1) % @n + 1
FROM @RandomNumber
|
Desired Output
Inspired by Ifor
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=189487
No comments:
Post a Comment