从表1插入* [英] Insert * from Table 1

查看:84
本文介绍了从表1插入*的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助,

我有两个表,表1是作为临时表写入的,这种情况会发生多次,直到按下存储按钮为止.
表2基本上是表1的副本,但也增加了今天的日期.有人会为此纠正我的c#/sql.目前,我已尝试使用

Please Help,

I have Two Tables, Table 1 is written to as a temporary table and this happens several times until a store button is pressed.
Table 2 is basically a carbon copy of Table 1 but also adds todays date. Would someone correct my c#/sql for this. Presently i have tried to use

SqlCommand updateTotalMade = new SqlCommand();
updateTotalMade.Connection = databaseConnection;

string sqlUpdateTotalMade = "Insert into Totalmade (FactoryID, AreaID, DaysNightsID, Product, Amount, RecordDate)
Select FactoryID, AreaID, DaysNightsID, Product, Amount from TempTotalMade and RecordDate = '" + String.Format("{0:u}", make.nextdate) + "'where FactoryID ='" + Vault.FACTORY + "' and AreaID = '" + Program.MAKE + "'";            

updateTotalMade.CommandText = sqlUpdateTotalMade;
updateTotalMade.ExecuteNonQuery();


推荐答案

string sqlUpdateTotalMade = "Insert into Totalmade (FactoryID, AreaID, DaysNightsID, Product, Amount, RecordDate)
Select FactoryID, AreaID, DaysNightsID, Product, Amount, getDate() from TempTotalMade  where FactoryID ='" + Vault.FACTORY + "' and AreaID = '" + Program.MAKE + "'";   



应该这样做






That should do it




<pre lang="c#">string sqlUpdateTotalMade = "Insert into Totalmade (FactoryID, AreaID, DaysNightsID, Product, Amount, RecordDate)
Select FactoryID, AreaID, DaysNightsID, Product, Amount, '" + String.Format("{0:u}", make.nextdate) + "' from TempTotalMade  where FactoryID ='" + Vault.FACTORY + "' and AreaID = '" + Program.MAKE + "'";   </pre>


如果这些字段一样,为什么要有两个表?

只需添加另一列:说TEMPORARY_FLAG.并使用您的代码进行区分.当您需要使记录合法化时,只需清除该标记即可.
If the fields are the same, why are you having two tables?

Just add another column: say TEMPORARY_FLAG. And use your code to distinguish between. When you need to legitimize the record just clear the flag.


Insert into Totalmade Select *, getDate() as RecordDate from TempTotalMade  where FactoryID ='" + Vault.FACTORY + "' and AreaID = '" + Program.MAKE + "'";


这篇关于从表1插入*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆