Pablo
Pablo

Reputation: 5087

merging rows from sql query result

What would it be the simplest way to merge a result like this from a sql query to be displayed in an asp.net gridview?

NULL   Tarde Fer  W. Lunes
Mañana NULL  Fer  W. Lunes

I need the result to look like this

Mañana Tarde Fer  W. Lunes

Upvotes: 1

Views: 99

Answers (2)

Martin Smith
Martin Smith

Reputation: 453287

Assuming Table

Col1      Col2     Col3    Col4
-------   ------   ------  --------
NULL      Tarde    Fer     W. Lunes
Mañana    NULL     Fer     W. Lunes

Then

SELECT MAX(Col1) AS Col1, MAX(Col2) AS Col2, Col3, Col4
FROM YourTable
GROUP BY Col3, Col4

Upvotes: 1

Beth
Beth

Reputation: 9607

Do it upstream from the UI (on the server returning the results, in other words,) and group on an ID field returning the max() field values when you want to exclude nulls.

Upvotes: 1

Related Questions