My datatable
| Date | Column1 | Column2 | Column3 |
|---|---|---|---|
| 01/10/2024 | Data1 | Data2 | NULL |
| 01/10/2024 | Data4 | Data5 | Data7 |
| 02/10/2024 | Data8 | Data9 | NULL |
| 02/10/2024 | Data1 | Data2 | NULL |
I want to concate Column1 and Column2 into one line if Column3 value is empty or NULL. If Column3 value is not empty or NULL then concate Column3 Only. When Column3 value available it concate only column3. How can i do it like below.
| Date | Concate |
| 01/10/2024 | Data1, Data2 |
| 01/10/2024 | Data7 |
| 02/10/2024 | Data8, Data9, Data1, Data2 |
Amit MohantyPosted Oct 29, 2024, 6:17 AM
Hey Debashish, try this:
Jignesh KumarPosted Oct 29, 2024, 11:20 AM
Hello,
You can use below query,
Vinoth XavierPosted Oct 29, 2024, 4:36 AM
Hi Debashish Mahonta,
Please check this.
Brahma Prakash ShuklaPosted Oct 23, 2024, 5:26 AM
Debashish MahontaPosted Oct 22, 2024, 3:21 PM
@Aman Gupta your query not working.
Aman GuptaPosted Oct 22, 2024, 9:36 AM
Hi Debashish,
Below is the updated query.
Debashish MahontaPosted Oct 22, 2024, 8:56 AM
What is error in my code? How to solve my code error?
Jayraj ChhayaPosted Oct 22, 2024, 6:50 AM
To achieve the desired concatenation based on the specified conditions, you can use the SQL
CASEstatement along with theCOALESCEfunction. Below is an example SQL query that demonstrates how to concatenateColumn1andColumn2whenColumn3is NULL, and to returnColumn3when it is not NULL.This query checks each row: if
Column3is NULL, it concatenatesColumn1andColumn2with a comma; otherwise, it returns the value ofColumn3. TheWHEREclause ensures that only rows with at least one non-null value are included in the result. AdjustYourDataTableto the actual name of your data table.