I have a view
Order Drink Entree Desert
--------------------------------------------------
12 Null Preparing Null
12 Ready NULL NULL
12 NULL NULL Waiting
I want to convert it to:
Order Drink Entree Desert
---------------------------------------------------
12 Ready Preparing Waiting
marc_s
9,0626 gold badges46 silver badges52 bronze badges
1 Answer 1
You can use an appropriate aggregation function. In this case, it seems like MIN
or MAX
will do the trick:
SELECT Order,
MIN(Drink) Drink,
MIN(Entree) Entree,
MIN(Desert) Desert
FROM dbo.YourTable
GROUP BY Order;
answered Apr 24, 2017 at 20:25
-
1That's what I would have done as well. If, of course, you might have more than one non-null row for the same order, then you'd have to figure out how to reconcile that.BradC– BradC2017年04月24日 20:27:57 +00:00Commented Apr 24, 2017 at 20:27
-
@BradC exactly, but there's no enough information in the sample dataLamak– Lamak2017年04月24日 20:30:09 +00:00Commented Apr 24, 2017 at 20:30
lang-sql
NULL
value on each row? Something is very wrong with the design that created this mess. Change theINSERT
ing code as soon as possible.