У меня есть SQL-запрос
SELECT DISTINCT DENSE_RANK()
OVER(ORDER BY bsContract.ContractNumber DESC) AS RANKS,
ROW_NUMBER()
OVER(PARTITION BY bsContract.ContractNumber ORDER BY bsContract.ContractNumber)
AS RowsNumber,
dbo.bsContract.ContractNumber,
Advertiser.OrganizationName AS Advertiser,
JobName AS Campaign,
bsContract.FromDate AS StartDate,
Advertiser.OrganizationName AS Client,
(ISNULL(bsContract.FirstName, '') + ' ' +
bsContract.LastName) AS ClientRep,
Advertiser.OrganizationName AS Vendor,
(ISNULL(bsContract.FirstName, '') + ' ' +
bsContract.LastName) AS 'VendorRep',
DocumentType,
FileType
INTO #temp
FROM dbo.bsContract
INNER JOIN Organization AS Advertiser
ON Advertiser.OrganizationID = bsContract.OrganizationID
WHERE FileType IS NULL
AND bsContract.ContractNumber = 'CR6520'
AND bsDocument.SellerID = 3632
SELECT DISTINCT Ranks,
(CASE
WHEN RowsNumber = 1 THEN
ContractNumber
ELSE
''
END) AS ContractNumber,
(CASE
WHEN RowsNumber = 1 THEN
Advertiser
ELSE
''
END) AS Advertiser,
(CASE
WHEN RowsNumber = 1 THEN
Campaign
ELSE
''
END) AS Campaign,
(CASE
WHEN RowsNumber = 1 THEN
StartDate
ELSE
(select convert(datetime, NULL))
END) AS StartDate,
Vendor,
VendorRep
FROM #temp
ORDER BY ContractNumber DESC
Все хорошо, это дает результат.В первой строке указано значение Contract Number, Advertiser Campaign, StartDate, Vendor and Vendor
Rep.
. Во 2-й строке значение ContractNumber, Advertiser, Campaign,
StartDate
совпадает, поэтому отображается как пустое.Но первая строка результата отображается дважды из-за Различного StartDate
.См. Прикрепленный скриншот:
Как решить эту проблему?