2

Result right now I am getting is:

EmployeeNo  Column1   Column2
================================
1           |  NULL       | Column2
1           |  Column1    |   NULL 

I want like

EmployeeNo  Column1   Column2
================================
1          | Column1  |   Column2

Kindly provide any help or way to do this

Thanks in advance

5

The simplest way to merge rows is with an aggregate function such as MIN/MAX. These functions will ignore nulls (see MSDN) and can operate similarly to ISNULL/COALESCE with aggregation. For example:

SELECT
  EmployeeNo,
  MAX(Column1) AS Column1,
  MAX(Column2) AS Column2
FROM MyTable
GROUP BY EmployeeNo

This will return the sample desired results. If your only goal is to merge columns with null values into rows with data in those columns, it doesn't matter whether you use MIN or MAX - the result set will be the same.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.