Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
SQL
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();

Thank you in anticipation.
Posted
Updated 14-Jun-12 3:47am
v2

C#
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


Edit:

SQL
<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>
 
Share this answer
 
v2
Comments
Davey85 14-Jun-12 10:14am    
Marq, Hi & Thanks, i should of mentioned that todays date isnt taken from the PC clock, it is an incremental DateTime based on the date of the last data entry to the main table. It would be better called 'next date'. So GetDate() didnt work, thanks for help though.
MarqW 14-Jun-12 10:16am    
I've added an edit. Basically it was the location of your final field, that you had put after the "FROM" section of the query
Davey85 14-Jun-12 11:09am    
Thanks so much, works a treat.
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.
 
Share this answer
 
SQL
Insert into Totalmade Select *, getDate() as RecordDate from TempTotalMade  where FactoryID ='" + Vault.FACTORY + "' and AreaID = '" + Program.MAKE + "'";
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900