Consolidating rows

i'm trying to consolidate my data into one row, just having a hard time grouping this information.

SELECT DISTINCT ccc.StartDate,ccc.StartTime,ccc.Enddate,ccc.EndTime,ccc.baseId,ccc.PegaIata,
CASE WHEN ccc.RowNumber = 1 THEN ccc.concessiontype ELSE NULL END AS ConcessionFeeAType,
CASE WHEN ccc.rowNumber = 1 THEN (ccc.taxrate) ELSE NULL END as ConcessionFeeA,
CASE WHEN ccc.RowNumber = 2 THEN ccc.concessiontype ELSE NULL END AS ConcessionFeeBType,
CASE WHEN ccc.rowNumber = 2 THEN (ccc.taxrate) ELSE NULL END as ConcessionFeeb
FROM
(
SELECT  DENSE_RANK() OVER(PARTITION BY a.baseid ORDER BY a.taxRate) AS RowNumber, '12/31/2017' AS StartDate, '11:59' AS StartTime, '' AS Enddate, '' AS EndTime, a.baseid,b.PegaIata,
a.concessiontype,a.taxRate
FROM concessions AS a
JOIN [Bases] AS b ON b.baseid = a.baseId
JOIN dbo.ProductCodes AS c ON c.productCode = a.productCode
LEFT OUTER JOIN [Bridge] AS d ON d.productCode = a.productCode 
WHERE c.fuelAssoc IS NULL AND a.taxRate <> 0) AS ccc

Open in new window


this image is what i'm currently getting. I'm trying to get this into one row.

Results I'm currently getting.
Southern_GentlemanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vitor MontalvãoMSSQL Senior EngineerCommented:
Your problem is with the CASE statements:
CASE WHEN ccc.RowNumber = 1 THEN ccc.concessiontype ELSE NULL END AS ConcessionFeeAType,
CASE WHEN ccc.rowNumber = 1 THEN (ccc.taxrate) ELSE NULL END as ConcessionFeeA,
CASE WHEN ccc.RowNumber = 2 THEN ccc.concessiontype ELSE NULL END AS ConcessionFeeBType,
CASE WHEN ccc.rowNumber = 2 THEN (ccc.taxrate) ELSE NULL END as ConcessionFeeb

Open in new window

As you have 2 rows, it will process 2 times and you can't do nothing unless you chance the SELECT in the FROM clause to return a single row.
0
Mark WillsTopic AdvisorCommented:
You could add in a GROUP BY
 GROUP BY ccc.StartDate,ccc.StartTime,ccc.Enddate,ccc.EndTime,ccc.baseId,ccc.PegaIata

Open in new window

and retrieve the MAX of the A and B columns
SELECT ccc.StartDate,ccc.StartTime,ccc.Enddate,ccc.EndTime,ccc.baseId,ccc.PegaIata,
MAX(CASE WHEN ccc.RowNumber = 1 THEN ccc.concessiontype ELSE '' END) AS ConcessionFeeAType,
MAX(CASE WHEN ccc.rowNumber = 1 THEN (ccc.taxrate) ELSE 0.0 END) as ConcessionFeeA,
MAX(CASE WHEN ccc.RowNumber = 2 THEN ccc.concessiontype ELSE '' END) AS ConcessionFeeBType,
MAX(CASE WHEN ccc.rowNumber = 2 THEN (ccc.taxrate) ELSE 0.0 END) as ConcessionFeeb
FROM
(
SELECT  DENSE_RANK() OVER(PARTITION BY a.baseid ORDER BY a.taxRate) AS RowNumber, '12/31/2017' AS StartDate, '11:59' AS StartTime, '' AS Enddate, '' AS EndTime, a.baseid,b.PegaIata,
a.concessiontype,a.taxRate
FROM concessions AS a
JOIN [Bases] AS b ON b.baseid = a.baseId
JOIN dbo.ProductCodes AS c ON c.productCode = a.productCode
LEFT OUTER JOIN [Bridge] AS d ON d.productCode = a.productCode 
WHERE c.fuelAssoc IS NULL AND a.taxRate <> 0) AS ccc
GROUP BY ccc.StartDate,ccc.StartTime,ccc.Enddate,ccc.EndTime,ccc.baseId,ccc.PegaIata

Open in new window

no need for select distinct if doing group by...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.