SQL - Destinct
HejJeg er ved at lave en simpel statestik, men "bookingnr" bliver vist 12 gange for hver post. Hvodan for jeg den til kun at vise én linie pr. booking?
SELECT [BOHO].[KUNDSPKEY] as Supplier
,[BOHO].[BOHOKEY] as BookingNo
,[BOHO].[FRAGTBETALER1] as PayingParty
,[BOHO].[KUNDMDKEY]
,[BOHO].[DATOBOHO] as ShipperDate
,[BOHO].[KUNDAFKEY] as ShipperNo
,[XALDB].[dbo].[KUND].[NAME] AS NameOfLoadingPlace
,[BOHO].[ADR3AF] as LoadingPostCity
,[BOHO].[LANDAFTX] as LoadingCountry
,[BOHO].[NAVNMD] as DeliveryName
,[BOHO].[ADR3MD] as DeliveryPostCity
,[BOHO].[LANDMDKEY] as DeliveryCountry
,[BOHO].[BEMTX1] as Comments1
,[BOHO].[BEMTX2] as Comments2
,[BOHO].[MRK1] as Comments3
,[BOHO].[CLL]
,[BOHO].[CTYPE]
,[BOHO].[BESK1]
,[BOHO].[NETKG]
,[BOHO].[BRTKG]
,[BOHO].[FRAGTKG1] as FreightKG
,[BOHO].[CBM]
,[BOHO].[LDM]
,[BOHO].[LOKAFORKEY] AS Actlocation
,[BOHO].[DATOFOR] AS ActDate
,[BOHO].[TIDSPUNKTFOR] as ActTime
,[BOHO].[LOKAAFGKEY] As DepartureLocation
,[BOHO].[DATOAFG] as DepartureDate
,[BOHO].[TIDSPUNKTAFG] as DepartureTime
,[BOHO].[LOKAANKKEY] as ArrivalLocation
,[BOHO].[DATOANK] as ArrivalDate
,[BOHO].[TIDSPUNKTANK] as ArrivalTime
,[BOHO].[LOKAEFTKEY] as ActArrivalLoc
,[BOHO].[DATOEFT] as ActArrivalDate
,[BOHO].[TIDSPUNKTEFT] as ActArrivalTime
FROM [XALDB].[dbo].[BOHO] join [XALDB].[dbo].[KUND]
ON [XALDB].[dbo].[BOHO].[FRAGTBETALER1] = [XALDB].[dbo].[KUND].[KUNDKEY]
WHERE [XALDB].[dbo].[BOHO].[DATASET] ='DAT'
AND [XALDB].[dbo].[KUND].[KUNDKEY] in ('8001280','6003400','3000366')
AND ([XALDB].[dbo].[BOHO].[DATOBOHO] >= DATEADD(mm, DATEDIFF(mm, 0, GETDATE()) - 1, 0))
AND ([XALDB].[dbo].[BOHO].[DATOBOHO] < DATEADD(mm, DATEDIFF(mm, 0, GETDATE()), 0))
ORDER BY [XALDB].[dbo].[BOHO].[BOHOKEY]