Hi - Below are the list of tables and task table is transaction table and user table is config table.
When we pick the task, user need to be assigned to each task on round robin basis. Any suggestion how to achive this through sql logic
;WITH cte_tasks AS (
SELECT *, ROW_NUMBER() OVER(ORDER BY TaskID) AS row_num
FROM #Task
),
cte_users AS (
SELECT *, ROW_NUMBER() OVER(ORDER BY userid) AS row_num
FROM #User
),
cte_total_users AS (
SELECT COUNT(*) AS total_users
FROM cte_users
)
SELECT *
FROM cte_tasks ct
INNER JOIN cte_users cu ON cu.row_num = ct.row_num %
((SELECT total_users FROM cte_total_users) + 1)
ORDER BY ct.TaskId