我无法在salesfacts表中插入值

时间:2016-02-01 08:06:34

标签: sql sql-server

我正在尝试将值插入到SalesFacts表中。但是,我受到了0行的影响。谁能告诉我代码有什么问题?任何帮助,将不胜感激。非常感谢你。

INSERT INTO 
  ClassicCars_Pte_LtdDW..SalesFacts(customerNumber, officeCode, productCode, employeeNumber, TimeKey, orderNumber, quantityOrdered, priceEach, buyPrice)
SELECT 
  cdim.customerNumber, dwoffice.officeCode, prod.productCode, em.employeeNumber, replace(CONVERT(DATE,o.OrderDate, 112),'-',''), od.orderNumber, od.quantityOrdered, od.priceEach, p.buyPrice
FROM
    ClassicCars_Pte_LtdOLTP..[Offices] office INNER JOIN ClassicCars_Pte_LtdOLTP..[Employees] e
    ON office.officeCode = e.officeCode

    INNER JOIN ClassicCars_Pte_LtdOLTP..[Customers] c
    ON e.employeeNumber = c.SalesrepEmployeeNumber

    INNER JOIN ClassicCars_Pte_LtdOLTP..[Orders] o
    ON c.customerNumber = o.customerNumber

    INNER JOIN ClassicCars_Pte_LtdOLTP..[OrderDetails] od 
    ON o.orderNumber = od.orderNumber

    INNER JOIN ClassicCars_Pte_LtdOLTP..[Products] p
    ON od.productCode = p.productCode

    INNER JOIN ClassicCars_Pte_LtdOLTP..[productLines] pro
    ON p.productLine = pro.productLine

    INNER JOIN ClassicCars_Pte_LtdDW..[OfficesDIM] dwoffice
    ON office.officeCode = dwoffice.officeCode

    INNER JOIN ClassicCars_Pte_LtdDW..[EmployeesDIM] em
    ON em.employeeNumber = e.employeeNumber

    INNER JOIN ClassicCars_Pte_LtdDW..[CustomersDIM] cdim
    ON c.customerNumber = cdim.customerNumber

    INNER JOIN ClassicCars_Pte_LtdDW..[ProductsDIM] prod
    ON prod.productCode = p.productCode

1 个答案:

答案 0 :(得分:0)

确保两件事: 1)运行查询的选择部分并确保它是否返回行。 2)确保链接服务器设置正确。最简单的方法是使用链接服务器名称从中选择一些东西:

从ClassicCars_Pte_LtdDW..SalesFacts中选择前10 * 从ClassicCars_Pte_LtdOLTP中选择前10 * .. [办公室]