Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
jchoudja
Starting Member
41 Posts |
Posted - 2013-03-29 : 12:36:57
|
Hi, I willike to add independant column to my table (Not included in the table)ExempleTable Artists (ArtistsID,ArtistName, ArtistsDOB)Table concerts (ArtistsID, ConcertDate, ConcertLocation)I want to produiceSELECT a.ArtistsID,a.ArtistName,c.ConcertDate,c.ConcertLocationFrom Artists a INNER JOIN Concerts c ON a.ArtistsID=c.ArtistsIDWhat should I add to get Rep=Manager (Rep is the column mane, Manager is the column Value)ArtistsID_|_ArtistName_|_ConcertDate_|_ConcertLocation_|_Rep---------------------------------------------------------------------1_________|_John_______|_03/10/2013__|_New York________|_Manager2_________|_Sony_______|_04/11/2013__|_Chicago_________|_Manager3_________|_Maria______|_05/12/2013__|_Houston_________|_ManagerThank you for your helpjc |
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2013-03-29 : 13:11:37
|
I'm not 100% sure I'm following your requirements, but maybe this? SELECT a.ArtistsID,a.ArtistName,c.ConcertDate,c.ConcertLocation, 'Manager' AS RepFrom Artists a INNER JOIN Concerts c ON a.ArtistsID=c.ArtistsID |
|
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2013-03-29 : 13:34:44
|
I'm even less sure that I'm following your requirements BUT if you want the literal string "Manager" to appear in your output, follow Lamprey's advice (usually a good idea anyway). If you want the name of the manager to appear and a Manager typically is attached to a single artist, then add a column to the Artist table using the ALTER TABLE command. If one manager has multiple artists then create a Manager table and define a foreign key relationship by adding a linking column in the Artist table using the ALTER TABLE and create the FOREIGN KEY constraint. If, on the other hand, I have completely missed the point of your requirements, ignore this post in its entirety.=================================================There are two kinds of light -- the glow that illuminates, and the glare that obscures. -James Thurber |
|
|
jchoudja
Starting Member
41 Posts |
Posted - 2013-04-02 : 10:49:49
|
Thank you. It worked with 'Manager' AS RepI have no control on tables. I use UNION ALL to link 2 queries manager is the same for each querie. jc |
|
|
|
|
|
|
|