1

私はSQLServerを初めて使用し、すべての顧客情報を含むビューを作成しようとしています。

これCustomerは、顧客が存在する場合に他のすべてのテーブルを取り込むメインテーブルです。

SQL Server Management Studioを使用してみましたが、結果がゼロでした。

これは、私が選択したテーブルの外観です。

ここに画像の説明を入力してください

他のテーブルの残りの列の外Corporationと外の分岐が必要です。AccountNumberAccount

これは、管理スタジオから提供されたものです。

SELECT     
   Customer.Customer.*, Customer.Miscellaneous2.*, Common.Address.*, 
   Company.CorporationStructure.Branch AS Expr1, Customer.Delivery.*, 
   Customer.Miscellaneous.*, Customer.Account.AccountNumber AS Expr2 
FROM         
   Customer.Account 
INNER JOIN
   Common.Address ON Customer.Account.AccountId = Common.Address.ForeignId 
INNER JOIN
   Company.CorporationStructure ON Customer.Account.CorporationStructureId = Company.CorporationStructure.CorporationStructureId 
                       AND Customer.Account.CorporationStructureId = Company.CorporationStructure.CorporationStructureId 
 INNER JOIN
    Customer.Customer ON Company.CorporationStructure.Branch = Customer.Customer.Branch 
 INNER JOIN
    Customer.Delivery ON Company.CorporationStructure.Branch = Customer.Delivery.Branch 
 INNER JOIN
    Customer.Miscellaneous ON Company.CorporationStructure.Branch = Customer.Miscellaneous.Branch 
 INNER JOIN
    Customer.Miscellaneous2 ON Company.CorporationStructure.Branch = Customer.Miscellaneous2.Branch

ゼロの結果を返します。

誰かが私が間違っているのを見ますか?

===更新===

提案されたようにクエリを更新しました:

SELECT     Customer.Customer.IsActive, Customer.Customer.CompanyCode, Customer.Customer.Branch, Customer.Customer.Account, Customer.Customer.TypeCompanyTank, 
                      Customer.Customer.SalesManCode, Customer.Customer.Name, Customer.Customer.Street, Customer.Customer.City, Customer.Customer.State, 
                      Customer.Customer.ZipCode, Customer.Customer.ZipCodeExtension, Customer.Customer.AreaCode, Customer.Customer.PhoneNumber, Customer.Customer.TaxCode, 
                      Customer.Customer.CreditCode, Customer.Customer.Type1, Customer.Customer.FinanceChargeCode, Customer.Customer.StatementInvoiceCode, 
                      Customer.Customer.OpenItemBalanceForward, Customer.Customer.BillingTransaction, Customer.Customer.BudgetChange, Customer.Customer.DelinquentLetter, 
                      Customer.Customer.PriceClassA, Customer.Customer.PriceClassB, Customer.Customer.PriceClassC, Customer.Customer.PriceClassR, 
                      Customer.Customer.InvoiceTerms, Customer.Customer.DefaultProductCode, Customer.Customer.DefaultUnitOfIssue, Customer.Customer.Type2, 
                      Customer.Customer.BillingCycle, Customer.Customer.CurrentBalance, Customer.Customer.Over30, Customer.Customer.Over60, Customer.Customer.Over90, 
                      Customer.Customer.Over120, Customer.Customer.PreviousStatmentBalance, Customer.Customer.DepositAmount, Customer.Customer.LastPaymenRecievedDate, 
                      Customer.Customer.LastPaymentRecievedAmount, Customer.Customer.BudgetRate, Customer.Customer.NonBudgetBalance, Customer.Customer.BudgetBalance, 
                      Customer.Customer.UnpaidFinanceCharges, Customer.Customer.StartDate, Customer.Customer.CreditRecord, Customer.Customer.CreditLimit, 
                      Customer.Miscellaneous2.IsActive AS Expr3, Customer.Miscellaneous2.CompanyCode AS Expr4, Customer.Miscellaneous2.Branch AS Expr5, 
                      Customer.Miscellaneous2.Account AS Expr6, Customer.Miscellaneous2.BillingCycleCode, Customer.Miscellaneous2.LatitudeDegree, 
                      Customer.Miscellaneous2.LatitudeDecimal, Customer.Miscellaneous2.North, Customer.Miscellaneous2.LongitudeDegree, 
                      Customer.Miscellaneous2.LongitudeDecimal, Customer.Miscellaneous2.West, Customer.Miscellaneous2.GEOResultCode, Customer.Miscellaneous2.DeliveryState, 
                      Customer.Miscellaneous2.DeliveryZipCode, Customer.Miscellaneous2.DeliveryZipCodeExtension, Customer.Miscellaneous2.RouteBook, 
                      Customer.Miscellaneous2.DriverRouteSequence, Customer.Miscellaneous2.StandingPurchaseOrderNumber, Customer.Miscellaneous2.PhoneType2, 
                      Customer.Miscellaneous2.AreaCode2, Customer.Miscellaneous2.PhoneNumber2, Customer.Miscellaneous2.PhoneType3, Customer.Miscellaneous2.PhoneNumber3, 
                      Customer.Miscellaneous2.EmailAddress, Customer.Miscellaneous2.ElectronicLetterOption, Customer.Miscellaneous2.ElectronicPostcardOption, 
                      Customer.Miscellaneous2.ElectronicStatementOption, Customer.Miscellaneous2.ElectronicInvoiceOption, Customer.Miscellaneous2.LossReason, 
                      Customer.Miscellaneous2.LossYear, Customer.Miscellaneous2.LossMonth, Customer.Miscellaneous2.GainReason, Customer.Miscellaneous2.GainYear, 
                      Customer.Miscellaneous2.GainMonth, Customer.Miscellaneous2.LastSalesActivityDate, Customer.Miscellaneous2.ElectricTankMonitorNumber, 
                      Common.Address.AddressId, Common.Address.ForeignId, Common.Address.AddressType, Common.Address.Street AS Expr7, Common.Address.City AS Expr8, 
                      Common.Address.State AS Expr9, Common.Address.ZipCode AS Expr10, Common.Address.ZipCodeExtension AS Expr11, Common.Address.FromFlatFile, 
                      Common.Address.IsUpdated, Common.Address.IsAdded, Common.Address.ClearUpdateAndAdded, Common.Address.CorporationId, 
                      Company.CorporationStructure.Branch AS Expr1, Customer.Delivery.CompanyCode AS Expr12, Customer.Delivery.Branch AS Expr13, 
                      Customer.Delivery.Account AS Expr14, Customer.Delivery.IsActive AS Expr15, Customer.Delivery.DegreeDayBase, Customer.Delivery.DeliveryCode, 
                      Customer.Delivery.UseCode, Customer.Delivery.PostcardInOutFlag, Customer.Delivery.Driver, Customer.Delivery.Route, Customer.Delivery.RouteSequence, 
                      Customer.Delivery.PreviousPercent, Customer.Delivery.PercentFull, Customer.Delivery.TankSerialNumber, Customer.Delivery.TankType, Customer.Delivery.TankUnit,
                       Customer.Delivery.TicketInOutFlag, Customer.Delivery.LockUseOrRateCode, Customer.Delivery.QuantityLastDelivered, Customer.Delivery.TankSize, 
                      Customer.Delivery.NumberOfTanks, Customer.Delivery.NumberOfCompanyTanks, Customer.Delivery.GallonsPerDegreeDay, Customer.Delivery.GallonsPerDay, 
                      Customer.Delivery.HeatingConfidence, Customer.Delivery.DailyConfidence, Customer.Delivery.LastDeliveryDate, Customer.Delivery.LastDeliveryDegreeDay, 
                      Customer.Delivery.OptimumDeliveryDateOrDegreeDay, Customer.Delivery.RunOutDeliveryDateOrDegreeDay, Customer.Delivery.GasCheck, 
                      Customer.Delivery.YearToDateDeliveries, Customer.Delivery.YearToDateGasDelivered, Customer.Delivery.TotalGasUsedLastYear, Customer.Delivery.AXGasUsed1, 
                      Customer.Delivery.AXGasUsed2, Customer.Delivery.AXGasUsed3, Customer.Delivery.AXGasUsed4, Customer.Delivery.AXGasUsed5, 
                      Customer.Delivery.AXDailyUsed1, Customer.Delivery.AXDailyUsed2, Customer.Delivery.AXDailyUsed3, Customer.Delivery.AXDailyUsed4, 
                      Customer.Delivery.AXDailyUsed5, Customer.Delivery.AXDays1, Customer.Delivery.AXDays2, Customer.Delivery.AXDays3, Customer.Delivery.AXDays4, 
                      Customer.Delivery.AXDays5, Customer.Miscellaneous.IsActive AS Expr16, Customer.Miscellaneous.CompanyCode AS Expr17, 
                      Customer.Miscellaneous.Branch AS Expr18, Customer.Miscellaneous.Account AS Expr19, Customer.Miscellaneous.CareOf, Customer.Miscellaneous.DeliveryStreet, 
                      Customer.Miscellaneous.DeliveryCity, Customer.Miscellaneous.PurchaseOrderNumber, Customer.Miscellaneous.MasterBillingBranch, 
                      Customer.Miscellaneous.MasterBillingAccount, Customer.Account.AccountNumber AS Expr2
FROM         Customer.Account LEFT OUTER JOIN
                      Common.Address ON Customer.Account.AccountId = Common.Address.ForeignId LEFT OUTER JOIN
                      Company.CorporationStructure ON Customer.Account.CorporationStructureId = Company.CorporationStructure.CorporationStructureId AND 
                      Customer.Account.CorporationStructureId = Company.CorporationStructure.CorporationStructureId LEFT OUTER JOIN
                      Customer.Customer ON Company.CorporationStructure.Branch = Customer.Customer.Branch LEFT OUTER JOIN
                      Customer.Delivery ON Company.CorporationStructure.Branch = Customer.Delivery.Branch LEFT OUTER JOIN
                      Customer.Miscellaneous ON Company.CorporationStructure.Branch = Customer.Miscellaneous.Branch LEFT OUTER JOIN
                      Customer.Miscellaneous2 ON Company.CorporationStructure.Branch = Customer.Miscellaneous2.Branch

今、私は結果を得ていますが、今、私は同じ顧客を何度​​も何度も得ています:

ここに画像の説明を入力してください

4

1 に答える 1

1

その理由は、おそらく会社の企業構造への二重結合のためです。問題の行は次のとおりです。

INNER JOIN
    Customer.Customer ON Company.CorporationStructure.Branch = Customer.Customer.Branch 
 INNER JOIN
    Customer.Delivery ON Company.CorporationStructure.Branch = Customer.Delivery.Branch 

fromCorporateStructure を句に 2 回 (顧客用に 1 回、配送用に 1 回) 表示する必要があります。

于 2013-01-18T16:40:18.400 に答える