Reputation: 57
I need to replace the blank value with the column Data2 Original Table
+-------+--------+
| data1 | Data2 |
+-------+--------+
| 45789 | 45789 |
| 56897 | 56897 |
| | 56897 |
| 56485 | 56485 |
| | 897458 |
+-------+--------+
Expected Table
+-------+--------+
| data1 | Data2 |
+-------+--------+
| 45789 | 45789 |
| 56897 | 56897 |
| 56897 | 56897 |
| 56485 | 56485 |
| 897458| 897458 |
+-------+--------+
I tried this not working
data1 == "" ? data1 : data2
Upvotes: 1
Views: 421
Reputation: 492
Your expression is true if two columns have the same data type. If data types are different, you need to cast the data2 column.
Enable data viewer to check your result, It works properly:
You can also use another way. Write a TSQL query to replace the Data1 column with Data2 Column
SELECT
CASE WHEN Data1 = '' THEN Data2 ELSE Data1 END Data1
,Data2
FROM YourTable
Upvotes: 2