I’m trying to create a BAQ to show all vendor list along with their contacts.
My current scenario is as follow:
Table = ERP.Vendor linked to ERP.VendorCnt
each vendor have multiple VendorCnt records, how do I display only the first vendorCnt records for every Vendor records? I’ve tried something like distinctTop but it doesn’t seem to work.
Example of current result:
Vendor = ABC
Contact = Lion, Tiger, Apple
select
[Vendor].[VendorNum] as [Vendor_VendorNum],
[Vendor].[VendorID] as [Vendor_VendorID],
[Vendor].[Name] as [Vendor_Name],
[SubQuery2].[VendCnt_Name] as [VendCnt_Name],
[SubQuery2].[Calculated_RowNumber] as [Calculated_RowNumber]
from Erp.Vendor as Vendor
left outer join (select
[VendCnt].[VendorNum] as [VendCnt_VendorNum],
[VendCnt].[Name] as [VendCnt_Name],
(ROW_NUMBER() over (partition by VendCnt.VendorNum order by VendCnt.Name)) as [Calculated_RowNumber]
from Erp.VendCnt as VendCnt) as SubQuery2 on
Vendor.VendorNum = SubQuery2.VendCnt_VendorNum
and ( SubQuery2.Calculated_RowNumber < 2 )