Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Team Scdule Round Robin

Author  Topic 

chiragvm
Yak Posting Veteran

65 Posts

Posted - 2014-12-30 : 02:26:59
Hi to all

i have to schedule 10 to 20 team within expected date range Like 01/01/2015 to 10/01/2015 (dd/mm/yyyy). with the use of round robin algorithm.
  • team-1 must play only once with remaining teams
  • one pair must come once.


Data

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tbl_Team](
[Id] [int] NOT NULL,
[TeamName] [nvarchar](50) NOT NULL
) ON [PRIMARY]

GO
INSERT [dbo].[tbl_Team] ([Id], [TeamName]) VALUES (1, N'Team1')
GO
INSERT [dbo].[tbl_Team] ([Id], [TeamName]) VALUES (2, N'Team2')
GO
INSERT [dbo].[tbl_Team] ([Id], [TeamName]) VALUES (3, N'Team3')
GO
INSERT [dbo].[tbl_Team] ([Id], [TeamName]) VALUES (4, N'Team4')
GO
INSERT [dbo].[tbl_Team] ([Id], [TeamName]) VALUES (5, N'Team5')
GO
INSERT [dbo].[tbl_Team] ([Id], [TeamName]) VALUES (6, N'Team6')
GO
INSERT [dbo].[tbl_Team] ([Id], [TeamName]) VALUES (7, N'Team7')
GO
INSERT [dbo].[tbl_Team] ([Id], [TeamName]) VALUES (8, N'Team8')
GO
INSERT [dbo].[tbl_Team] ([Id], [TeamName]) VALUES (9, N'Team9')
GO
INSERT [dbo].[tbl_Team] ([Id], [TeamName]) VALUES (10, N'Team10')
GO

-------------
Chirag
India
Sr.Software Engineer

viggneshwar
Yak Posting Veteran

86 Posts

Posted - 2015-01-08 : 09:40:51
select a.id aid, a.TeamName aTeam, b.id bid, b.TeamName bTeam
from [tbl_Team] a
cross join [tbl_Team] b
where a.Id < b.Id

Regards
Viggneshwar A
Go to Top of Page
   

- Advertisement -