Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2004
    Posts
    38

    Unanswered: Statement converting Columner to Tabular

    I'm building a website for my local hockey league and need to do something that I'm not sure can be accomplished with a SQL statement.. I have two tables with the following fields relevant to my question:

    tblTeams:
    intTeamID

    tblGames:
    intGameID
    intAwayTeamID
    intHomeTeamID


    Records in tblGames would look like:
    intGameID , intAwayTeamID , intHomeTeamID
    1 , 1 , 2
    2 , 3 , 4
    3 , 1 , 4
    4 , 2 , 3

    This columner structure works well for 80% of what I need to do.

    However, for the other 20% I need it to be tabular. Like this:

    intGameID , intTeamID , strTeamLoc
    1 , 1 , Away
    1 , 2 , Home
    2 , 3 , Away
    2 , 4 , Home
    3 , 1 , Away
    3 , 4 , Home
    4 , 2 , Away
    4 , 3 , Home


    It's the same data, just shown differently. I can get what I need by adding a third table to the mix, but that entails extra data entry. It would be much nicer to have a SQL statement that shows me columner data in the tabular format (or vice versa)..

    Any ideas?

    (sorry for the goofy attempt at showing data, I'm not sure how to show it correctly here..)

  2. #2
    Join Date
    Oct 2004
    Posts
    38
    Duh... Nevermind.. That was easy..

    Select intGameID, intHomeTeamID
    UNION
    Select intGameID, intAwayTeamID

    I didn't know you could do a union on two fields from the same table..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •