Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9096657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:54:24+00:00 2026-06-16T23:54:24+00:00

I have a query that returns 2 columns, 1 being ‘time’ which is not

  • 0

I have a query that returns 2 columns, 1 being ‘time’ which is not unique and may have up to 4 occurrences. The 2nd column is a list of ‘names’. If need be I can easily add a third field which is unique to this data called RegId.

I want to modify the results of the query in such a way that I reduce the time column down to one instance (GROUP BY), but I want to show all names horizontally across in a table format similar to below.

'Start Time'  'Player 1'   'Player 2'   'Player 3'  'Player 4'

So far I have unsuccessfully tried to use the PIVOT command but may just be missing a trick on that one. Is there a straight forward command I should be using?

The closest closest I’ve gotten to it is as follows:

DECLARE @Registered TABLE
(CompetitionName VARCHAR(50),
CompetitionDate  Date,
StartTime TIME,
PlayersName  Varchar(60)
)
INSERT INTO @Registered
SELECT MAX(c.CompetitionName) AS 'Competition Name', MAX(c.[Date]) AS 'Competition Date', 
CONVERT(VARCHAR, r.PlayersStartTime, 108) AS 'Start Time', 
CASE WHEN m.MemberId IS NOT NULL THEN (m.Surname + ', ' + m.FirstName) ELSE (nm.Surname + ', '+ nm.Firstname) END AS PlayersName
FROM dbo.Competitions c
LEFT JOIN [dbo].[Registration] r ON c.[CompetitionId] = r.[CompetitionId]
LEFT JOIN dbo.Members m ON r.MemberId = m.MemberId
LEFT JOIN dbo.NonMembers nm ON r.NonMemberId = nm.NonMemberId
WHERE Date = '2013-01-04' AND c.CompetitionId = 10
GROUP BY r.PlayersStartTime, m.MemberId, m.FirstName, m.Surname, nm.FirstName, nm.Surname
----
SELECT [@Registered].StartTime, [@Registered].PlayersName AS 'Player 1', [@Registered].PlayersName AS 'Player 2',
[@Registered].PlayersName AS 'Player 3',[@Registered].PlayersName AS 'Player 4'
FROM @Registered

Any ideas would be very gratefully appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T23:54:25+00:00Added an answer on June 16, 2026 at 11:54 pm

    Here is a trick to get a comma separated list — I bet this is what you want:

    It will look like this:

    StartTime    PlayerList
    5:00         Sam, David, Joe
    6:00         Lisa, Bart, Victor
    

    To do that use a query like this (the XML “trick”)

    SELECT DISTINCT Main.StartTime, 
     STUFF((SELECT ', ' + PlayersName
      FROM [@Registered] Inner
      WHERE Inner.StartTime = Main.StartTime 
      FOR XML PATH ('')),1,2,'') AS PlayerList
    FROM [@Registered] Main
    

    Note, I did not test so it might have a typo (but I doubt it)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Sql-Server, and I have the below query which returns all columns that
I have the following query which returns the following error: An aggregate may not
I have a query that always returns one row, with many columns. I would
I have a query that returns me around 6 million rows, which is too
I have a sub query that returns one column, showing as GroupType, I then
I have this query that returns the results by ordering it by focus.name ASC.
I have a query that returns Properties for Rent / Sale on their respective
I have a query that returns a result set similar to the one below:
I have a query that returns a string, as well as an escape character
i have a query that returns rows that i want, e.g. QuestionID QuestionTitle UpVotes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.