Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Statement converting Columner to Tabular

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-13-04, 17:52
EndBoards EndBoards is offline
Registered User
 
Join Date: Oct 2004
Posts: 38
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..)
Reply With Quote
  #2 (permalink)  
Old 10-13-04, 18:02
EndBoards EndBoards is offline
Registered User
 
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..
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On