使用INNER JOIN和预定值插入

时间:2013-12-27 21:04:24

标签: sql sql-server join

我正在尝试将9500左右的记录添加到来自不同表的表中,问题是我正在添加它们的表具有极大量的colums,而我从中拉出的表非常规范化所以我不太确定如何对它进行内连接,这是我到目前为止所做的:

INSERT INTO Products (Code, ManufacturerId, VendorId, IsActive, Name, NamePlural, ShortDescription, Description, UpSellMessage, Cost, Price, IsOnSale, SalePrice, IsShipable, ShipPrice, Weight, Length, Width, Height, HasCountryTax, HasStateTax, HasLocalTax, DateAdded, Keywords, Inventory_Tracked, DropShip, DownloadOneTime, DealTimeIsActive, MMIsActive, ProductType, RecurringSubscriptionPrice, PaymentPeriod, Term, BillingDelay, SaleType, BundleGroupID, ComputePrice, PriceUp, PriceChangedAmount, PriceChangedType, SwatchesPerRow, ChangeOnClick, ChangeOnMouseover, ShowCloseUpLink, LinkBigImage, SwatchAllignment, DescriptionAllignment, DetailLink)
FROM otherProducts table2
INNER JOIN table2
VALUES (table2.col1, 1, 1, 0, table2.col1, table2.col1, table2.col4, table2.col4, 'some message that does not matter', table2.col3, table2.col2, 0, '0', 1, '8', '3', '8', '8', '8', 1, 1, 1, '12/27/2013', ' ', 0, 0, 0, 0, 0, 0, 0, '0', 0, 0, 0, 0, 0, 1, '0', 0, 0, 0, 0, 0, 0, 0, 0, table2.col1+'.aspx');

我可以看到这是一个巨大的混乱,它只是给我错误,任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:2)

您需要insert . . . select语法:

INSERT INTO Products (Code, ManufacturerId, VendorId, IsActive, Name, NamePlural, ShortDescription, Description, UpSellMessage, Cost, Price, IsOnSale, SalePrice, IsShipable, ShipPrice, Weight, Length, Width, Height, HasCountryTax, HasStateTax, HasLocalTax, DateAdded, Keywords, Inventory_Tracked, DropShip, DownloadOneTime, DealTimeIsActive, MMIsActive, ProductType, RecurringSubscriptionPrice, PaymentPeriod, Term, BillingDelay, SaleType, BundleGroupID, ComputePrice, PriceUp, PriceChangedAmount, PriceChangedType, SwatchesPerRow, ChangeOnClick, ChangeOnMouseover, ShowCloseUpLink, LinkBigImage, SwatchAllignment, DescriptionAllignment, DetailLink)
    select table2.col1, 1, 1, 0, table2.col1, table2.col1, table2.col4, table2.col4, 'some message that does not matter', table2.col3, table2.col2, 0, '0', 1, '8', '3', '8', '8', '8', 1, 1, 1, '12/27/2013', ' ', 0, 0, 0, 0, 0, 0, 0, '0', 0, 0, 0, 0, 0, 1, '0', 0, 0, 0, 0, 0, 0, 0, 0, table2.col1+'.aspx'
    FROM otherProducts table2;

我认为你根本不需要做join