If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > Pivot, Case, or ???

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-05-12, 20:14
stharish stharish is offline
Registered User
 
Join Date: Jan 2012
Posts: 3
Pivot, Case, or ???

Hello,

(SQL Server 2008 R2)

I have a list of flight legs with columns:

[Date] [Trip#] [LegID] [Account] [DepartureTime] [Origin] [Dest] [ArrivalTime] [DisplayName]

The [DisplayName] column contains the names of passengers associated with a particular [LegID]. The problem is when there are more than 1 passengers on a particular leg I'm get a new row for each passenger name. For example, LegID 1234 is displaying 4 times since there are 4 passengers listed for that leg.

Ideally I would like to add columns for each passenger for a particular leg called pax1, pax2, pax3, pax4, etc. Unfortunately passengers are not given assignments like passenger1, passenger2, etc. Is there a way to do this? FYI, each passenger (user) does have a unique UserID.

Please help!

Last edited by stharish; 01-05-12 at 20:34.
Reply With Quote
  #2 (permalink)  
Old 01-06-12, 13:12
Wim Wim is offline
Registered User
 
Join Date: Nov 2004
Posts: 1,280
The data model looks OK to me. Don't touch it. You'll make things worse.

People come to this forum to ask how they can deal with a data model like the one you seem to want to achieve. They get the advice to normalise it to your current data model.

Don't touch it.
__________________
With kind regards . . . . . SQL Server 2000/2005/2008/2008 R2 Earned beers: 16
Wim
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald Knuth
Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages
Reply With Quote
  #3 (permalink)  
Old 01-06-12, 15:34
stharish stharish is offline
Registered User
 
Join Date: Jan 2012
Posts: 3
Sorry if I wasn't clear. I'm not tying to modify the database. This is strictly for reporting purposes using Report Builder 3.0. I'm just trying to query the existing database to create a report showing each flight leg and associated passengers. I'm a beginner so I don't know a whole lot about more complicated queries.

Hope this helps.

Thanks
Reply With Quote
  #4 (permalink)  
Old 01-06-12, 21:27
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Would it not be more appropriate to have your report grouped so that all passengers information was shown below each individual flight leg, rather than columnar?

To do this write a query joining the flight leg and passenger tables and in the report builder at a section/grouping by flight. The wizard should be able to help you perform this
__________________
George
Twitter | Blog
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

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