如图A,B 两个表需要根据A表的每个part_number查询B表的description,vendor,vendor_part,vendor_part_status,restriction_code,restriction列。更新到表C
对于每一项,如果相同在Dx列就显示S,不同就显示D.
另外对于A中的 part_number,如果B中含有的Vendor在A中没有,也需要跟新到C中。
我原来想取出a中的每条信息然后根据part_number查询b,然后再根据结果写C.奈何“初学者”哦。请各位大侠帮个忙看看,最好能有简单的SQL查询语句可以实现目的。原来的想法..
try
{
if (conn.State == ConnectionState.Closed)
conn.Open(); objCommand.CommandText = "select * from a where 1=1";
/* for (int id = 0; id < 100; id++)
{
objCommand.CommandText = "select * from a where id=" + id;
SqlDataReader ds = objCommand.ExecuteReader();
string pn = "", vendor = "";
if (ds.Read())
{
pn = ds[2].ToString();
vendor = ds[4].ToString();
ds.Close();
} if (pn != "" && vendor != "")
{
objCommand1.CommandText = "select * from b where EMC_Part= " + pn+" " + "and Vendor=" + vendor;
} SqlDataReader ds1 = objCommand1.ExecuteReader();
。 }
*/
}
catch (SqlException exx)
{
MessageBox.Show(exx.Message.ToString());
}
finally
{
//关闭数据库连接
label2.Text = "Compare Successfully.";
Update();
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
}
可能文图描述的不是很清楚,A表中的part_number 必须在B表中找到。因为B表是一个可供选择的总单。如果找不要需要报错。(re标注)
PN当等的时候就比较discription,vendor,vendor_pn 等。PN和discription原则上是一一对应的,但是它们可能有许多不同的vendor.当vendor 相同的时候就接着比较别的类别,当PN的vendor 在B表中有而A表中没有的话也需要插入到C表新的一行。A表和B表的这些比较项都要插入C表,比如discription,A表的列插入C表的discription,B表的列插入C表的E_disc.然后C表的D1列用来显示两者S(ame)/D(ifferent).