I am getting duplicate rows of data.
The wh.whsheaderID is different and it corresponds to a particular unit and to a particular reference (hence my "duplicate values"). Then I have a datetime for NOT departure and then a different datetime for THU departure.
However, because there are 2 different wh.whsheaderIDs corresponding to the same unit and the same reference I get 2 rows of data where the NOT departure date & scan date will be populated and on the next row, the THU departure date & scan time will be populated. How do I collate this information into one row?
SELECT wh.WhsHeaderID,
mu.Number AS Unit ,
m.MovementRef AS Reference ,
(SELECT CASE WHEN COUNT(*) >=2 THEN 'Yes' ELSE 'No' END FROM dbo.whsHeader WHERE RunMovID = m.movementId) AS [Co-Load],
(Select wh.ArrDepDate where wh.localdepotcode = 'NOT') AS [NOT Departure Date],
(Select wh.LastScannedTime where wh.LocalDepotCode = 'NOT') AS [NOT Last Scan] ,
(Select wh.ArrDepDate where wh.LocalDepotCode = 'THU') as [THU Departure Date],
(Select wh.LastScannedTime where wh.LocalDepotCode = 'THU') as [THU Last Scan],