This article is half-done without your Comment! *** Please share your thoughts via Comment ***
Check the below input data and expected output to generate the Row number without default function.
Input Data:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
id ----------- 55 99 33 11 22 87 25 36 48 54 36 |
Expected Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
id RowNumber ----------- ----------- 11 1 22 2 25 3 33 4 36 6 36 6 48 7 54 8 55 9 87 10 99 11 |
Create a table with data:
1 2 3 4 5 6 7 |
CREATE TABLE tbl_Numbers (id int) GO INSERT INTO tbl_Numbers VALUES (55),(99),(33),(11),(22),(87),(25),(36),(48),(54),(36) GO |
Solution:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
;with CTE as ( select id ,id + rand() as new_id from tbl_Numbers ) select id, (select count(*) from CTE t where t.new_id <= CTE.new_id ) as RowNumber from CTE order by id |
Please try the different solution for this puzzle and share it via comment...