SQL将联接结果存储到新的数据库表中

汉克IT

这是我的SQL查询,它使用join合并SQL数据库上的两个表,因此我想将结果发送到新创建的数据库SAP_Mat_StoreBGA_test

但是,我的查询不起作用,请帮忙。

foreach (DataRow row2 in dt1.Rows)
{
    query4 = "SELECT * FROM SAP_Mat_StoreBGA BGA LEFT JOIN SAP_Mes_BuildPlan ON SAP_Mes_BuildPlan.SMT_Assembly = BGA.Component WHERE BGA.Component like '73%'" 
             + "INSERT INTO SAP_Mat_StoreBGA_test (BGA.Material, BGA.Component, SMT_Assembly) VALUES('" + row2["BGA.Material"]+ "','" + row2["BGA.Component"] + "','" + row2["SMT_Assembly"] + "')";

    CheckingCommand.ExecuteNonQuery();
}
穆雷尼克

您可以使用插入选择

INSERT INTO SAP_Mat_StoreBGA_test (BGA.Material, BGA.Component, SMT_Assembly)
SELECT BGA.Material, BGA.Component, SMT_Assembly FROM SAP_Mat_StoreBGA BGA 
LEFT JOIN SAP_Mes_BuildPlan ON SAP_Mes_BuildPlan.SMT_Assembly = BGA.Component
WHERE BGA.Component like '73%'

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章