Deal the cards to the players


Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

-- @ is the table containing the input 
-- column c is the value of the card, column a is the position on the card in the deck
-- @n is the number of players

DECLARE @ table(a int identity(0,1), c varchar(9))
DECLARE @n int = 4

INSERT @ values('1a'),('2c'),('3e'),('4g'),('5i'),('6k')

SELECT string_agg(c,',')FROM @ GROUP BY a%@n

Enter Parameters

Switch sites:
loading Hold tight while we fetch your results