N
.Net Sports
I am trying to get all the sales reps and their combined sales totals
for a given queried date, in which i loop thru (using C# while loop)
the available sales reps to get their rep IDs, then match it up with
their sales results for the day. The portion of my code below is
successful in retrieving all the necessary rep IDs; now I have to loop
thru the rep IDs and match their sales total for the given day, whereas
the each individual sale is represented with the Order_ID. When running
this in my Query Analyzer, i notice that it only gives me just one sale
per sales rep on the given date, and not the second or third sale if
multiple sales exist for the sales rep on this date. Since this is
being looped with the While control statement (and it reads the data
reader until there are no more available sales rep IDs), what can I add
to the While statement to make sure it grabs all the Order_Ids, and
then adds them up in the aggregate SUM statement?
--
string sqlRep = "SELECT SalesRep.ID as repID , SalesRep.LName " +
"FROM SalesRep " +
"WHERE (Terminated IS NULL) AND (tblSalesRep.StartDate < '" +
QueriedDay + "') " +
"order by SalesRep.ID asc ";
SqlCommand objCommandDR = new SqlCommand(sqlRep, objConn);
objConn.Open();
///
////-/ = SqlCommand.ExecuteReader();
SqlDataReader drRep = objCommandDR.ExecuteReader();
// main query
while (drRep.Read())
{
repID = drRep.GetInt32(drRep.GetOrdinal("repID"));
LName = drRep.GetString(drRep.GetOrdinal("LName"));
strSQL = "SELECT SalesRep.ID, SalesRep.LName,
SUM(Accounts.totalsales) AS totalsalesQueriedDay " +
"FROM SalesRep INNER JOIN " +
"Orders ON SalesRep.ID = Orders.SalesRep_ID INNER JOIN " +
"Accounts ON Orders.ID = Accounts.Order_ID " +
"WHERE Accounts.TDate = '" + QueriedDay + "' AND SalesRep.ID =
'" + repID + "' " +
"GROUP BY SalesRep.ID, SalesRep.LName " +
"HAVING (SUM(Accounts.totalsales) >= 0) " +
"ORDER BY SalesRep.LName";
////-/Debug.WriteLine(strSQL);
// create an instance of the command-connxt object
SqlCommand objCommand = new SqlCommand(strSQL, objConn2);
objConn2.Open();
SqlDataReader drTotalsales = objCommand.ExecuteReader();
}
for a given queried date, in which i loop thru (using C# while loop)
the available sales reps to get their rep IDs, then match it up with
their sales results for the day. The portion of my code below is
successful in retrieving all the necessary rep IDs; now I have to loop
thru the rep IDs and match their sales total for the given day, whereas
the each individual sale is represented with the Order_ID. When running
this in my Query Analyzer, i notice that it only gives me just one sale
per sales rep on the given date, and not the second or third sale if
multiple sales exist for the sales rep on this date. Since this is
being looped with the While control statement (and it reads the data
reader until there are no more available sales rep IDs), what can I add
to the While statement to make sure it grabs all the Order_Ids, and
then adds them up in the aggregate SUM statement?
--
string sqlRep = "SELECT SalesRep.ID as repID , SalesRep.LName " +
"FROM SalesRep " +
"WHERE (Terminated IS NULL) AND (tblSalesRep.StartDate < '" +
QueriedDay + "') " +
"order by SalesRep.ID asc ";
SqlCommand objCommandDR = new SqlCommand(sqlRep, objConn);
objConn.Open();
///
////-/ = SqlCommand.ExecuteReader();
SqlDataReader drRep = objCommandDR.ExecuteReader();
// main query
while (drRep.Read())
{
repID = drRep.GetInt32(drRep.GetOrdinal("repID"));
LName = drRep.GetString(drRep.GetOrdinal("LName"));
strSQL = "SELECT SalesRep.ID, SalesRep.LName,
SUM(Accounts.totalsales) AS totalsalesQueriedDay " +
"FROM SalesRep INNER JOIN " +
"Orders ON SalesRep.ID = Orders.SalesRep_ID INNER JOIN " +
"Accounts ON Orders.ID = Accounts.Order_ID " +
"WHERE Accounts.TDate = '" + QueriedDay + "' AND SalesRep.ID =
'" + repID + "' " +
"GROUP BY SalesRep.ID, SalesRep.LName " +
"HAVING (SUM(Accounts.totalsales) >= 0) " +
"ORDER BY SalesRep.LName";
////-/Debug.WriteLine(strSQL);
// create an instance of the command-connxt object
SqlCommand objCommand = new SqlCommand(strSQL, objConn2);
objConn2.Open();
SqlDataReader drTotalsales = objCommand.ExecuteReader();
}