简体   繁体   English

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

[英]SQL store the join result into a new database table

This is my SQL query that use join to merge two table on SQL database, therefore I would like to sent the result to newly created database, SAP_Mat_StoreBGA_test .这是我的 SQL 查询,它使用 join 合并 SQL 数据库上的两个表,因此我想将结果发送到新创建的数据库SAP_Mat_StoreBGA_test

However, my query is not working, please help.但是,我的查询不起作用,请帮助。

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();
}

You could use an insert-select您可以使用插入选择

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%'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM