Rohin

Rohin

  • NA
  • 13
  • 891

How can I group data with same value in multiple rows, in two columns?

Feb 24 2022 11:11 AM

I have some data in a SQL server table with different To and CC recipients listed in two columns.

Is it possible to get different data sets with all rows that have the same values in To and CC columns?

Would it be easier to split the datatable in my C# code?

Suppose I have data like this :

  A       B       C       To            CC
-----   -----   -----    -----         -----
  132    45     test     em1@cc        ec7@cc
  133    34     new      em4@cc        ec3@cc
  134    65     here     em3@cc        ec5@cc
  135    78     one      em7@cc        ec4@cc
  136    45     check    em1@cc        ec5@cc
  137    85     two      em6@cc        ec1@cc
  138    56     email    em1@cc        ec5@cc
  139    65     var      em3@cc        ec5@cc

I would like to get the data separated as below (Rows where To value is same, and CC value is same):

  A       B       C       To            CC
-----   -----   -----    -----         -----
  132    45     test     em1@cc        ec7@cc


  A       B       C       To            CC
-----   -----   -----    -----         -----
  133    34     new      em4@cc        ec3@cc

  A       B       C       To            CC
-----   -----   -----    -----         -----
  134    65     here     em3@cc        ec5@cc
  139    65     var      em3@cc        ec5@cc

  A       B       C       To            CC
-----   -----   -----    -----         -----
  135    78     one      em7@cc        ec4@cc

  A       B       C       To            CC
-----   -----   -----    -----         -----
  136    45     check    em1@cc        ec5@cc
  138    56     email    em1@cc        ec5@cc


  A       B       C       To            CC
-----   -----   -----    -----         -----
  137    85     two      em6@cc        ec1@cc

Answers (2)