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 3801184
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:00:36+00:00 2026-05-19T14:00:36+00:00

Imagine a student and multiple professors A professor has many students The students go

  • 0

Imagine a student and multiple professors
A professor has many students
The students go to class at the same time and date.

Table1

ClassName  | ProfessorName |StudentsPresent|ClassStartTime    |ClassDate  |ClassID
Philosophy | Stewart       |10             |8:00              |01/29/2011 | 1
Philosophy | Kyle          |10             |8:00              |01/29/2011 | 1
Religion   | Myke          |11             |8:30              |01/29/2011 | 2
Religion   | Nancy         |11             |8:30              |01/29/2011 | 2

How would I go about getting the following result

ClassName  | ProfessorName |StudentsPresent|ClassStartTime    |ClassDate  |ClassID
Philosophy | Stewart,Kyle  |10             |8:00              |01/29/2011 | 1
Religion   | Myke,Nancy    |11             |8:30              |01/29/2011 | 2

As we speak I am researching cursors.

  • 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-05-19T14:00:36+00:00Added an answer on May 19, 2026 at 2:00 pm

    Your table seems to be very denormalized. I’ve heard that cursors are a terrible thing within SQL Server and should be avoided if you can. With it how it is, put into a table called Schedule, this is how I might fulfill your request.

    DECLARE @Schedule TABLE
    (
        ClassName VARCHAR(50)
        , ProfessorName VARCHAR(50)
        , StudentsPresent INT
        , ClassStartTime TIME
        , ClassDate DATE
        , ClassID INT
    );
    
    INSERT INTO @Schedule
    VALUES ('Philosophy', 'Stewart', 10, '8:00', '20110129', 1)
        , ('Philosophy', 'Kyle', 10, '8:00', '20110129', 1)
        , ('Religion', 'Myke', 11, '8:30', '20110129', 2)
        , ('Religion', 'Nancy', 11, '8:30', '20110129', 2);
    
    WITH UniqueClasses AS
    (
        SELECT DISTINCT
            ClassName
            , ClassStartTime
            , StudentsPresent
            , ClassDate
            , ClassID
        FROM @Schedule
    )
    SELECT
        ClassName
        ,   (
                STUFF((
                        SELECT
                            ',' + ProfessorName
                        FROM @Schedule Schedule
                        WHERE Schedule.ClassID = UniqueClasses.ClassID
                        FOR XML PATH('')
                    ) , 1, 1, '')
            )AS ProfessorName
        , StudentsPresent
        , StudentsPresent
        ,  ClassStartTime
        , ClassDate
        , ClassID
    FROM UniqueClasses
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So imagine 2 big mysql tables imported from Excel. Table1 has the field SNameID,
Imagine a hypothetical object with a number of attributes: pseudocode: class Student { Name:
Imagine an object you are working with has a collection of other objects associated
Imagine there is a jar (named lib.jar ) that contains a single class and
Imagine the following code, written in C#: public class Provider<T> { T GetValue(); //
Imagine we have a set of entities each of which has its state: free,
i have a doubt. Imagine that i have three categories: student, worker, student/worker. the
Imagine I store everything on the server according to the server's date. However, when
Imagine a user sitting at an Ethernet-connected PC. He has a browser open. He
Imagine the following code: class foreach_convert { public static void method2() { List<IComparable> x

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.