Sub query as multiline column

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mariusvg
    New Member
    • Mar 2007
    • 3

    Sub query as multiline column

    I'm relatively new with mssql. I would like to know whether there is any way to display the results from a subquery as a multiline Column.

    For Example:

    Select a.SectionID,
    ListOfEmployees = (Select b.Name From Employees b Where b.SectionId = a.SectionId)
    From Sections a



    I dont know if somthing like this is possible.
  • mabubakarpk
    New Member
    • Feb 2007
    • 62

    #2
    Yes, you can do this.

    Comment

    • Mariusvg
      New Member
      • Mar 2007
      • 3

      #3
      Originally posted by mabubakarpk
      Yes, you can do this.
      Great!!! but how?? The way I use in my example keeps giving me an error, complaining about the subquery returning multiple rows

      Comment

      • AricC
        Recognized Expert Top Contributor
        • Oct 2006
        • 1885

        #4
        Originally posted by Mariusvg
        Great!!! but how?? The way I use in my example keeps giving me an error, complaining about the subquery returning multiple rows
        Look at this example if it doesn't help give us an idea of how your tables are laid out in the DB. In the format below so we can easily tell what is where.
        TTeams
        intTeamID (PK)
        strTeam

        TPlayers
        intPlayerID (PK)
        strFirstName
        strMiddle
        strLastName

        etc...

        Then some SQL

        SELECT strLastName + ', ' + strFirstName + ', ' + strMiddleName AS strFullName FROM TPlayers

        Comment

        Working...