title: getting a sum in columns from different tables in a sqlserver-ce database and displaying the result in a label control
body: <p>I have a sqlserver compact database with five tables A, B, C, D and E. There is no relation defined between the tables. All the tables have an <code>amount</code> column where I need to get the sum from the first four tables and subtract the sum from table E (i.e calculate if I should get a profit or a loss). I have searched for problems pertaining the same to no avail.</p>
  
  <p>What I expect to get: <code>sum(A)+sum(B)+sum(C)+sum(D)-sum(E)</code>, which is to be defined as a command text passed to a <code>sqlcecommand</code> object. The result is to be displayed in a label control.</p>
  
  <p>this is what I have so far:</p>
  
  <pre><code>SqlCeCommand sqlCommand = new SqlCeCommand();
              login = login.getLogin();
              SqlCeDataReader sqlDataReader;
  
              string cmdString =
                  "SELECT SUM(AmountReceived) FROM A WHERE Date BETWEEN (@param1) AND (@param2);" +
                  "SELECT SUM(AmountCharged) FROM B WHERE DateOfEntry BETWEEN (@param1) AND (@param2);" +
                  "SELECT SUM(Amount) FROM C WHERE Date BETWEEN (@param1) AND (@param2);" +
                  "SELECT SUM(AmountCharged) FROM D WHERE DateOfRequest BETWEEN (@param1) AND (@param2);" +                
                  "SELECT SUM(AmountDue) FROM E WHERE Date BETWEEN (@param1) AND (@param2);";
  
              sqlCommand.Connection = login.connection;
              sqlCommand.CommandType = CommandType.Text;
              sqlCommand.CommandText = cmdString;
              sqlCommand.Parameters.Add("@param1", SqlDbType.DateTime).Value = dateTimePickerFromPandL.Text;
              sqlCommand.Parameters.Add("@param2", SqlDbType.DateTime).Value = dateTimePickerToPandL.Text;
              sqlDataReader = sqlCommand.ExecuteReader();
  
              if (sqlDataReader.Read())
              {
  
                  labelProfitOrLossAmount.Text = "Ksh : " + //value expected to go here
  
              }
  </code></pre>
  
  <p>Where do I go from here?</p>