Aggregate Functions in DataTable.Select

  • Thread starter Thread starter Marcel Hug
  • Start date Start date
M

Marcel Hug

Hi NG!
With a Inner-Join SQL I get my datas in a DataSet.
In the table are the column Entry and Version.

Like this:

Entry Version
1 1
1 2
1 3
2 1
3 1


Now i would like to have just the newest version of each entry.
Entry Version
1 3
2 1
3 1

I tried to use the
DataTable.Select(MAX(Version), Entry)...
DataTable.Select(MAX(Version) GROUP BY Entry)...

But it does not work and I did not find some good help.
I would like the keep my Inner Join SQL without this MAX and Group by,
because of use in other locations

Thanks
Regards
 
Hi,

I tried to use the
DataTable.Select(MAX(Version), Entry)...
DataTable.Select(MAX(Version) GROUP BY Entry)...


The DataTable/DataView is not a SQL engine therefore you cannot use TSQL .

In your particular case, it's stated in the MSDN that there will be not
group by feature, but all the rows will have the same value (when using an
aggregate)

why don't you do this in the SQL server? , frankly I think it's the only
solution.
 
| I tried to use the
| DataTable.Select(MAX(Version), Entry)...
| DataTable.Select(MAX(Version) GROUP BY Entry)...
Have you tried DataTable.Compute?

http://msdn.microsoft.com/library/d...frlrfsystemdatadatatableclasscomputetopic.asp

NOTE: You will need to manually do the Group By, I normally scan the first
table, building a second table with all the unique groupings. For each
unique group I would use DataTable.Compute on the first table with the
unique group as part of the filter...

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| Hi NG!
| With a Inner-Join SQL I get my datas in a DataSet.
| In the table are the column Entry and Version.
|
| Like this:
|
| Entry Version
| 1 1
| 1 2
| 1 3
| 2 1
| 3 1
|
|
| Now i would like to have just the newest version of each entry.
| Entry Version
| 1 3
| 2 1
| 3 1
|
| I tried to use the
| DataTable.Select(MAX(Version), Entry)...
| DataTable.Select(MAX(Version) GROUP BY Entry)...
|
| But it does not work and I did not find some good help.
| I would like the keep my Inner Join SQL without this MAX and Group by,
| because of use in other locations
|
| Thanks
| Regards
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top