Wrox Programmer Forums
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 30th, 2008, 11:37 AM
Authorized User
 
Join Date: Jul 2006
Posts: 22
Thanks: 1
Thanked 0 Times in 0 Posts
Default Grouping DataTable results

I have a stored procedure that returns a CustomerID from SAP and joins with a SQL Server 2000 table. With the count (return_cnt) involved, the grouping must also contain CustomerID and Regio. I have to return the CustomerID to the DataTable in order to get the Regio from SAP, but when I do that, states (Regio) appear separately with their respective counts because the CustomerID is different yet belongs to the same global group. Since these are all part of the same global group, I need to be able to then group the results from the stored proc by state.

How do I take the results in this DataTable, ignore the CustomerID column and re-group the results by Regio?

CODE:

public DataTable getReturnsByLocation(string global_name, string place_id, string model_id, string start_date, string end_date, bool exclude_npf_abuse, string rc_ctry, CustomersFromSAP oCustomersFromSAP, string[] asCustomerIDs)
        {
            ArrayList alCustomerIDLists = ConvertToCustomerIDLists(asCustomerIDs);

            SqlConnection cn = new SqlConnection(connString);
            cn.Open();
            SqlCommand cmd = new SqlCommand("getReturnsByLocation", cn);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@place_id", place_id));
            cmd.Parameters.Add(new SqlParameter("@model_id", model_id));
            cmd.Parameters.Add(new SqlParameter("@start_date", start_date));
            cmd.Parameters.Add(new SqlParameter("@end_date", end_date));
            cmd.Parameters.Add(new SqlParameter("@exclude_npf_abuse", exclude_npf_abuse));
            cmd.Parameters.Add(new SqlParameter("@rc_ctry", rc_ctry));
            for (int iIndex = 0; iIndex < alCustomerIDLists.Count; iIndex++)
            {
                cmd.Parameters.Add(new SqlParameter("@psCustomerIDs" + (iIndex + 1), SqlDbType.VarChar, 8000)).Value = alCustomerIDLists[iIndex];
            }

            DataSet ds = new DataSet();
            da.Fill(ds, "tablex");
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                DataRow drCustomerInfo = oCustomersFromSAP.GetCustomerInfo((string)row["CustomerID"]);
                row["Regio"] = drCustomerInfo["Regio"];
            }
            ds.Tables[0].AcceptChanges();
            ds.Tables[0].Select();
            return ds.Tables[0];
        }

------------- stored proc ---------------------------------------
CREATE PROCEDURE dbo.getReturnsByLocation

(
@place_id varchar(30),
@model_id varchar(30),
@start_date datetime,
@end_date datetime,
@exclude_npf_abuse varchar(30),
@rc_ctry varchar(30),
@psCustomerIDs1 varchar(8000),
@psCustomerIDs2 varchar(8000) = NULL,
@psCustomerIDs3 varchar(8000) = NULL,
@psCustomerIDs4 varchar(8000) = NULL,
@psCustomerIDs5 varchar(8000) = NULL,
@psCustomerIDs6 varchar(8000) = NULL,
@psCustomerIDs7 varchar(8000) = NULL,
@psCustomerIDs8 varchar(8000) = NULL,
@psCustomerIDs9 varchar(8000) = NULL,
@psCustomerIDs10 varchar(8000) = NULL,
@psCustomerIDs11 varchar(8000) = NULL,
@psCustomerIDs12 varchar(8000) = NULL
)
AS

--
-- Create temp table with the list of customer IDs.
--
CREATE TABLE #TempCustomerIDs (CustomerID varchar(16))
INSERT INTO #TempCustomerIDs
    SELECT CustomerID FROM
        fnParseCustomerIDs(
            @psCustomerIDs1,
            @psCustomerIDs2,
            @psCustomerIDs3,
            @psCustomerIDs4,
            @psCustomerIDs5,
            @psCustomerIDs6,
            @psCustomerIDs7,
            @psCustomerIDs8,
            @psCustomerIDs9,
            @psCustomerIDs10,
            @psCustomerIDs11,
            @psCustomerIDs12)

        select
                count(serial_id_rcv) return_cnt, CustomerID, Regio

        from
                (select distinct notification_id, model_id, serial_id_rcv, return_reason, rpr_cntr_state, received_dt, t.CustomerID, '' as Regio
                  from Repairs r join #TempCustomerIDs t on r.customer_ship_to = t.CustomerID
                  where (received_dt between @start_date and @end_date) and REPAIR_TYPE = 'D'
                  and model_id = @model_id
                  and customer_ship_to = @place_id
                  and NPF_FLAG = 'N'
                          and ABUSE_FLAG = 'N') tbl
        group by Regio, CustomerID
        order by count(serial_id_rcv) desc


DROP TABLE #TempCustomerIDs
GO






Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get the value from the DataTable column Dmitriy Pro VB 6 4 March 30th, 2010 08:58 AM
Datatable Limno .NET Framework 1.x 0 May 28th, 2008 02:37 PM
DataTable Update smithsf22 Visual Studio 2005 1 May 1st, 2008 06:26 PM
Edit Query Results in Results Grid druid2112 SQL Server 2005 1 June 28th, 2007 08:49 AM
Protect cells and allow grouping/un-grouping sfreuden Excel VBA 4 December 14th, 2006 08:01 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.