Shaik Ali

Shaik Ali

  • NA
  • 46
  • 967

Update Table Based on Select Statment

Jun 30 2019 11:33 AM
Dear Experts
 
i am using two queries to update a talbe it work fine.
but i would like to convert this into one query. please Guide me
 
try
{
OleDbCommand cmd1 = new OleDbCommand(@"SELECT BID, SUM( IIF( TTYPE IN ('P','R','T','I') ,(Qty+QtyFree) ,0 )) AS TOT_IN,
SUM( IIF(TTYPE IN ('S','B','N','O') ,(Qty+QtyFree) , 0)) AS TOT_OUT,
SUM( IIF(TTYPE IN ('A') ,(Qty+QtyFree) , 0)) AS TOT_ADJ, TOT_IN - TOT_OUT + TOT_ADJ AS TOT_STK From Detail where BID = '" + bid + "' GROUP BY BID", cn); //and [HEADER] <> '" + dgvRestQty.Rows[i].Cells["HEADER"].Value + "'
dr = cmd1.ExecuteReader();
if (dr.Read())
{
OleDbCommand cmd11 = new OleDbCommand("update BATCH set QinHand = " + dr["TOT_STK"].ToString() + " where BID = '" + bid + "' ", cn);
cmd11.ExecuteNonQuery();
}
}
catch { }
 
thanks you 
 

Answers (2)