SqlServer用SQL语句将查出的数据直接插入到另一个张的表中
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'
)