Distinct with subset of fields from typedview

Posts   
 
    
jovball
User
Posts: 443
Joined: 23-Jan-2005
# Posted on: 14-Jun-2006 08:18:14   

Is it possible to get a distinct output of several (not all) fields from a typed view?

For example, the typed view has these fields (and perhaps others as well): CustomerID OrderDate ProductID

I'd like to get a distinct output of CustomerID and ProductID only. Can this be done and if so, how can it be done.

Joel Reinford Data Management Solutions LLC

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 14-Jun-2006 14:50:10   

I think you mean to Group By CustomerID and ProductID, right?

If so then you might use a the groupByClause parameter in one of the FetchTypedView overloads (Adapter model), or one of the YourTypedView.Fill overloads (SelfServicing)

jovball
User
Posts: 443
Joined: 23-Jan-2005
# Posted on: 14-Jun-2006 18:18:25   

No, I don't want to group. I just want distinct on a subset of columns.

Given this View

CREATE VIEW dbo.vw_OrderKeys    
AS
SELECT
    o.OrderID
     ,o.CustomerID
     ,o.EmployeeID
     ,o.OrderDate
     ,d.ProductID
    
FROM
    [dbo].[Orders] o
    JOIN dbo.[Order Details] d
    ON o.OrderID = d.OrderID

I want to do this equivalent:

SELECT Distinct
    k.CustomerID
    ,k.ProductID
FROM dbo.vw_OrderKeys k

Typically I'd be adding some predicate expression onto that to limit the results.

Joel Reinford Data Management Solutions LLC

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 14-Jun-2006 19:08:25   

Create a dynamic list with the 2 fields you want to have. Then specify for 'allowDuplicates' false and fetch the dynamic list into a datatable.

Frans Bouma | Lead developer LLBLGen Pro