Concat columns with NULL values in Snowflake SQL

If you use concat functions in Snowflake, if there any of the column is having a NULL value, it returns the value as NULL.

To avoid that, we can use array_construct and array_to_string as below: 

select array_to_string(array_construct([column1], [column2], [column3]),'|') 

If the values for Column1 = 'abc', Column2=NULL, Column3 ='xyz', then the above query return the output as 'abc||xyz'


No comments:

Post a Comment

How to run UPDATE/INSERT/DELETE Statements on Azure SQL Database in Microsoft Fabric Notebook...

You can run UPDATE/INSERT/DELETE Statements on Azure SQL Database in Microsoft Fabric Notebook using Python SQL Driver - pyodbc.  For the Fa...