0

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
asked Apr 24, 2017 at 20:22
1
  • 1
    I know this isn't the question you asked, but why on Earth do you have only one column with a non-NULL value on each row? Something is very wrong with the design that created this mess. Change the INSERTing code as soon as possible. Commented Apr 25, 2017 at 0:48

1 Answer 1

5

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
2
  • 1
    That'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. Commented Apr 24, 2017 at 20:27
  • @BradC exactly, but there's no enough information in the sample data Commented Apr 24, 2017 at 20:30

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.