SqlServer用SQL語句將查出的資料直接插入到另一個張的表中
阿新 • • 發佈:2020-12-26
SqlServer用SQL語句將查出的資料直接插入到另一個張的表中
示例程式碼:
INSERT INTO dbo.Barcode ( BarNo , FiscalYear , FiscalMonth , BarType , ItemId , ItemName , WhId , WhName , CurrentWhId , CurrentWhName , ItemQty , LotNo , StUserId , StUserName , StDatetime , RKVou , CKVou , DeprecatedUserId , DeprecatedUserName , DeprecatedFalg ) ( select A.bar_no AS [BarNo], A.fiscal_year AS [FiscalYear], A.fiscal_month AS [FiscalMonth], A.bar_type AS [BarType], A.item_no AS [ItemId], A.item_name AS [ItemName], 4 AS [WhId], A.wh_name AS [WhName], 0 AS [CurrentWhId], '' AS [CurrentWhName], A.item_qty AS [ItemQty], A.lot_no AS [LotNo], a.st_user_id AS [StUserId], A.st_user_name AS [StDatetime], A.st_datetime AS [StDatetime], A.rk_vou AS [RKVou], A.ck_vou AS [CKVou], 0 AS [DeprecatedUserId], '' AS [DeprecatedUserName], A.deprecated_falg AS [DeprecatedFalg] FROM OPENROWSET('SQLOLEDB','127.0.0.1';'sa';'123',HTMDB.dbo.TabBarcode) AS A WHERE bar_type = 'K' )