Friday, March 23, 2012

Link problem in my script file

I have a script file that I need to change the link because the view is leaving out some records. The problem description follows the script.

The script is:

CREATE view v_Flight_Check(Flight_No, Doc_No, Flight_Doc_No, Leg_no, Actual_Departing_Date, Actual_Arriving_Date,
Flight_Legs, Actual_Hours, Actual_Over_Load, Actual_Landings, Actual_Air_Time, Flight_Type_A, Flight_Type_B,
Aircraft_Id, Doc_Status,Aircraft_Doc_No,LogBookPage, Actual_From_Airport,Actual_To_Airport, Actual_Flight_Legs, FLActual_Hours, FLActual_Over_Load,
Start_ECU_Airframe_Hrs, End_Ecu_Airframe_Hrs, End_Ecu_Ac_hrs,
Crew,Position, From_Leg_Doc_No, To_Leg_Doc_No,Last_Name, First_Name, Tail_No,HSN,Serial_No,RECORD_TYPE) AS

SELECT DISTINCT Flight_Log.Flight_No,Flight_Log_Leg.Doc_no, Flight_Log_Leg.Flight_Doc_No, Flight_Log_Leg.Leg_no, Flight_Log_Leg.Actual_Departing_Date, Flight_Log_Leg.Actual_Arriving_Date,
Flight_Log_Leg.Flight_Legs, Flight_Log_Leg.Actual_Hours, Flight_Log_Leg.Actual_Over_Load, Flight_Log_Leg.Actual_Landings, Flight_Log_Leg.Actual_Air_Time, Flight_Log_Leg.Flight_Type_A, Flight_Log_Leg.Flight_Type_B,
Flight_Log.Aircraft_Id, Flight_log.Doc_Status, Flight_Log.Aircraft_Doc_No,Flight_Log.LogBookPage, Flight_Log.Actual_From_Airport,Flight_Log.Actual_To_Airport, Flight_Log.Actual_Flight_Legs, Flight_Log.Actual_Hours, Flight_Log.Actual_Over_Load,
Flight_Log.Start_ecu_Airframe_hrs, Flight_Log.End_ECU_Airframe_hrs,Flight_Log.End_ecu_ac_hrs,
Flight_Log_Crew.User_code,Flight_Log_Crew.Position, Flight_Log_Crew.From_Leg_Doc_No, Flight_Log_Crew.To_Leg_Doc_No, Userlist.L_name,UserList.F_Name,Aircraft_hdr.tail_no,Aircraft_hdr.hsn, Aircraft_Hdr.Serial_No,'FL'

FROM GDB_01_4.dbo.FLIGHT_LOG,
GDB_01_4.dbo.Aircraft_HDR,
GDB_01_4.dbo.Flight_Log_leg Right Outer Join
GDB_01_4.dbo.FLIGHT_LOG_CREW ON GDB_01_4.dbo.FLIGHT_LOG_CREW.FLIGHT_LOG_DOC_NO = GDB_01_4.dbo.FLIGHT_LOG_LEG.FLIGHT_DOC_NO,
GDB_01_4.dbo.Userlist

Where Flight_Log.Doc_No = Flight_Log_Leg.Flight_Doc_No and
FLIGHT_LOG_LEG.DOC_NO >= fLIGHT_LOG_CREW.FROM_LEG_DOC_NO AND FLIGHT_LOG_LEG.DOC_NO <= fLIGHT_LOG_CREW.TO_LEG_DOC_NO and
Flight_Log_Crew.User_Code = Userlist.ccode and Flight_Log.Aircraft_Doc_No = Aircraft_Hdr.Doc_No

The problem is that if there was no crew listed on the Flight Leg, the entire flight and leg is left off. I need all of the records in the FLight Leg Table, even if no crew was listed.

Does anyone know how I can fix this? My script writing skills are minimal.

Thanks

SBoyd

You need to move some of the conditions in the WHERE clause to the OUTER JOIN ON clause. This should provide the results you are looking for. It is however hard to tell which conditions without looking at some data and the relationship between the tables in detail.

No comments:

Post a Comment