Extract Unique Values from Database

  • Thread starter Thread starter Prasun
  • Start date Start date
P

Prasun

Hello:

I am trying to extract the unique rows from a child table. Currently I am
set the create contraints vaue in the datarelationship to False. Because of
this, it will ignore the unique values in the child table. I want to be able
to figure out how to know which rows are unique.

Here are the DataRelationships


Code:


RelProcCode = New DataRelation("ProcCodeTC", ParentCol, Child1Col, False)
XLFileMainDS.Relations.Add(RelProcCode)
RelProcCode1 = New DataRelation("ProcCode26", ParentCol,
Child2Col, False)
XLFileMainDS.Relations.Add(RelProcCode1)





Here is the code to access the child rows and do the necessary changes


Code:

For Each DataRowMain In XLFileMainDS.Tables("TableWithMain").Rows
For Each DataRowTC In DataRowMain.GetChildRows(RelProcCode)
DataRowMain("Tech Amt") = DataRowTC("Amt")
DataRowMain("Tech Allowed") = DataRowTC("Allowed
Amount")
Next
For Each DataRow26 In DataRowMain.GetChildRows(RelProcCode1)
DataRowMain("Prof Amt") = DataRow26("Amt")
DataRowMain("Prof Allowed") = DataRow26("Allowed
Amount")
Next
Next





Thank You
Prasun
 
Is there a way to pick out uinque rows out of a database (excel file in my
case). I will try to illustrate my case with an example


Type Code Mod222 5678 G
222 5678 B
222 5678
222 3456 G
222 3456 B
222 3456
222 9876 G
222 1234
222 7890
222 7890 B
222 2121
222 2121 G



I want my data table to be filled with

Type Code Mod

222 5678
222 3456
222 9876
222 1234
222 7890
222 2121


Is there a way i can do this through the SELECT command i send through the
connection to fill the datatable
 
Hi,

Yes, you could do this using DISTINCT clause in your SELECT statement, but
it will select distinct combination of the values. For example, next
statement will select distinct rows based on combination of two fields

SELECT DISTINCT Field1, Field2 FROM MyTable
 
Is it possible for the statement to be written as follows

SELECT Field1, DISTINCT Field 2 FROM MyTable

thank you
Prasun
 
Hi,

Using this DISTINCT syntax you cannot select all the values for the field1
and just a distinct values for the field2. It actually doe snot make any
sense. What you could do is to use select with just one field and DISTINCT.
It will select only unique values from this field
 
Back
Top