Select b.Code as MasterCode, b.CompanyName as MainAgentName, b.ShortName as MainAgentID, pfcb.UserName as MainUserName, pfcb.UPassword as MainPassword, b.LogoExt as MainAgentLogoExt, b.AccomDiscount as MainDiscount, b.AccomDiscountType as MainDiscountType, b.DiscountFlag as MainDiscountFlag, b.DiscountLevel as MainDiscountLevel, b.LogoActive as MainAgentLogoActive,b.CurrencyCode as MainCurrencyCode,b.BranchCode as MainBranchCode,b.CurrencyFollowSub as CurrencyFollowSub, a.LogoExt,a.Code as Code,a.ShortName as ShortName,a.PfType,a.EpayFlag,a.OSCancelDay,a.LogoActive as subAgentLogoActive,pfc.Code as PfUserCode,pfc.PrefixCode, pfc.UserName as UserName,pfc.Email as Email,pfc.Name as Name,pfc.Surname as Surname,a.AccAddress as AccAddress, a.Address1 as Address1,a.Address2 as Address2,a.Address3 as Address3,a.CityCode as CityCode, a.CountryCode as CountryCode,a.Zipcode as Zipcode,a.AccomDiscount as Discount,a.AccomDiscountType as DiscountType, pfc.Department as Department,pfc.mPosition as mPosition,pfc.Telno as Telno, a.Telno as AgentTelno,a.Email as AgentEmail,a.Website as AgentWebsite,a.BankAccountCode as AgentBankAccountCode, a.AccLongname as AccLongname,a.CompanyName as CompanyName,pfc.Mobileno as Mobileno,pfc.Facsimile as Facsimile, a.BranchCode as BranchCode,a.Facsimile as AgentFacsimile,a.CurrencyCode as CurrencyCode,a.DiscountFlag as DiscountFlag,a.MasterFlag as WLMasterFlag, a.UnActiveWLBarFlag, a.cMarkUpType,a.cMarkUpAmount,a.sMarkUpType,a.sMarkUpAmount,a.SaleFlag,pfc.B2BMaster,pfc.B2BAdmin,pfc.B2BAuthorizations From pfs a, pfs b, pfcontacts pfc, pfcontacts pfcb, pfservicegroups pfs Where a.MasterCode = 'MA1605000003' AND a.MasterCode not in ('NONE','ALL','') AND b.MasterCode not in ('') AND a.Code = pfc.PfCode AND b.Code = pfcb.PfCode AND a.Code =pfs.Code AND a.MasterCode = b.Code AND a.ShortName = 'JLT1STD' AND pfc.UserActive='Y' AND pfcb.UserActive='Y' AND pfs.GroupCode = 'AGENT' AND pfcb.B2BMaster = 'Y' Order By a.Code