| Author |
Topic |
|
motilok
Starting Member
24 Posts |
Posted - 2010-10-04 : 10:11:47
|
| I have the following data in my tableGuest_ID Guest_NameDriver1Guest_PickUpDateTime1Guest_PickUpLocation1Guest_DropOffDateTime1Guest_DropOffLocation1Driver2Guest_PickUpDateTime2Guest_PickUpLocation2Guest_DropOffDateTime2Guest_DropOffLocation2I need to create Drivers' schedule report with following columnsDriver ***Guest_IDGuest_NameGuestPickUpDateTime (combined Guest_PickUpDateTime 1 & 2, sorted Asc)GuestPickUpLocation (combined Guest PickUpLocation 1& 2)GuestDropOffDateTime (combined Guest_DropOffDateTime 1&2)GuestDropOffLocation (combined Guest_DropOffLocation 1&2) PS Not sure how to go about driver, since Driver 1 and Driver 2 can be same or different and reports needs to be for one driver without any extra information. Example:Guest_ID - 15, 201, 103Guest_Name - Jack Smith, Bill Johnson, Amy SlonDriver1 - Billy, Jim, EricGuest_PickUpDateTime1 - 10/15/2010 6am, 10/14/2010 8 am, 10/16/2010 9pmGuest_PickUpLocation1 - Avalon, PID, AirportGuest_DropOffDateTime1 - 10/15/2010 6:30 am, 10/14/2010 8:15 am, 10/16/2010 9:45 pmGuest_DropOffLocation1 - PID, LaQuinta, MarriottDriver2 - Billy, Billy, JimGuest_PickUpDateTime2 - 10/16/2010 9:30am, 10/17/2010 12:15 pm, 10/17/2010 1:00 pmGuest_PickUpLocation2 - PID, LaQuinta, MarriottGuest_DropOffDateTime2 - 10/16/2010 10:00am, 10/17/2010 12:30 pm, 10/17/2010 1:15 pmGuest_DropOffLocation2 - Airport, PID, PIDThis is what I want it to be:Driver: BillyGuest_ID: 15, 15, 201Guest_Name: Jack Smith, Jack Smith, Bill JohnsonGuestPickUpDateTime: 10/15/2010 6am, 10/16/2010 9:30 am, 10/17/2010 12:15pmGuestPickUpLocation: Avalon, LaQuinta, LaQuintaGuestDropOffDateTime: 10/15/2010 6:30am, 10/16/2010 10:00am,10/17/2010 12:30 pmGuestDropOffLocation: PID, Airport, PID |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-10-04 : 10:39:08
|
| can you post it in correct format please?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
motilok
Starting Member
24 Posts |
Posted - 2010-10-05 : 09:22:27
|
| I have the following data in my tableTripID,Guest_ID,Guest_Name,Driver1,Guest_PickUpDateTime1,Guest_PickUpLocation1,Guest_DropOffDateTime1,Guest_DropOffLocation1,Driver2,Guest_PickUpDateTime2,Guest_PickUpLocation2,Guest_DropOffDateTime2,Guest_DropOffLocation2148, 35, John Smith, Andrew, 10/15/2010 06:00 am, ERI, 10/15/2010 06:30 am, PID, John, 10/16/2010 1:00 am, PID, 10/16/2010 1:30 am, MarriottI need Driver's Schedule Looking like thisDriver (Driver1 & Driver2),TripID, Guest_ID,Guest_Name,GuestPickUpDateTime (combined Guest_PickUpDateTime 1 & 2, sorted Asc),GuestPickUpLocation (combined Guest PickUpLocation 1& 2),GuestDropOffDateTime (combined Guest_DropOffDateTime 1&2),GuestDropOffLocation (combined Guest_DropOffLocation 1&2)ROW1: Andrew, 148, 35, John Smith, 10/15/2010 06:00 am, ERI, 10/15/2010 06:30 am, PIDROW2: John, 148,35,John Smith, 10/16/2010 01:00 am, PID, 10/16/2010 1:30 am, MarriottDoes this make sence? I really don't know how to put it in a better and more proper format. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-10-05 : 12:21:06
|
ok. you can do it as followsSELECT Driver1 AS Driver,TripID,Guest_ID,Guest_Name,Guest_PickUpDateTime1 AS GuestPickUpDateTime,Guest_PickUpLocation1 AS GuestPickUpLocation,Guest_DropOffDateTime1 AS GuestDropOffDateTime,Guest_DropOffLocation1 AS GuestDropOffLocationFROM TableUNION ALLSELECT Driver2,TripID,Guest_ID,Guest_Name,Guest_PickUpDateTime2,Guest_PickUpLocation2,Guest_DropOffDateTime2,Guest_DropOffLocation2FROM Table ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
motilok
Starting Member
24 Posts |
Posted - 2010-10-05 : 13:56:29
|
| You are the SQL Wizard! You have no Idea how much I love you!!! I got exactly what I want, my drivers would be happy to see their schedule neat and organized... :) |
 |
|
|
motilok
Starting Member
24 Posts |
Posted - 2010-10-12 : 08:43:36
|
| This is not really a new question, but more of a continuation of my previous question in this postPreviously I had this: TripID,Guest_ID,Guest_Name,Driver1,Guest_PickUpDateTime1,Guest_PickUpLocation1,Guest_DropOffDateTime1,Guest_DropOffLocation1,Driver2,Guest_PickUpDateTime2,Guest_PickUpLocation2,Guest_DropOffDateTime2,Guest_DropOffLocation2148, 35, John Smith, Andrew, 10/15/2010 06:00 am, ERI, 10/15/2010 06:30 am, PID, John, 10/16/2010 1:00 am, PID, 10/16/2010 1:30 am, MarriottThanks to visakh16, I got this:Driver (Driver1 & Driver2),TripID, Guest_ID,Guest_Name,GuestPickUpDateTime (combined Guest_PickUpDateTime 1 & 2, sorted Asc),GuestPickUpLocation (combined Guest PickUpLocation 1& 2),GuestDropOffDateTime (combined Guest_DropOffDateTime 1&2),GuestDropOffLocation (combined Guest_DropOffLocation 1&2)ROW1: Andrew, 148, 35, John Smith, 10/15/2010 06:00 am, ERI, 10/15/2010 06:30 am, PIDROW2: John, 148,35,John Smith, 10/16/2010 01:00 am, PID, 10/16/2010 1:30 am, MarriottNow I need to add one more column Status (arriving or leaving), so the data needs to look like this:Driver (Driver1 & Driver2),TripID, Guest_ID,Guest_Name,GuestPickUpDateTime (combined Guest_PickUpDateTime 1 & 2, sorted Asc),GuestPickUpLocation (combined Guest PickUpLocation 1& 2),GuestDropOffDateTime (combined Guest_DropOffDateTime 1&2),GuestDropOffLocation (combined Guest_DropOffLocation 1&2), StatusROW1: Andrew, 148, 35, John Smith, 10/15/2010 06:00 am, ERI, 10/15/2010 06:30 am, PID, ArrivingROW2: John, 148,35,John Smith, 10/16/2010 01:00 am, PID, 10/16/2010 1:30 am, Marriott, DepartingArriving - if the data was pulled from GuestPickUpDateTime 1 (or any other column with 1)Departing - if the data was pulled from GuestPickUpDateTime 2 (or any other column with 2) |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-10-17 : 02:54:08
|
seems like you just need a derived column moreSELECT Driver1 AS Driver,TripID,Guest_ID,Guest_Name,Guest_PickUpDateTime1 AS GuestPickUpDateTime,Guest_PickUpLocation1 AS GuestPickUpLocation,Guest_DropOffDateTime1 AS GuestDropOffDateTime,Guest_DropOffLocation1 AS GuestDropOffLocation,'Arriving' AS StatusFROM TableUNION ALLSELECT Driver2,TripID,Guest_ID,Guest_Name,Guest_PickUpDateTime2,Guest_PickUpLocation2,Guest_DropOffDateTime2,Guest_DropOffLocation2,'Departing'FROM Table ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
motilok
Starting Member
24 Posts |
Posted - 2010-10-19 : 10:32:14
|
| thank you, you saved me once again. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-10-19 : 12:42:19
|
| welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|