How to replace NULL to specific string in snowflake (SQL) - snowflake-cloud-data-platform

Does anyone know how to replace NULL to specific string in snowflake (SQL)?
Before
ID
Name
1
Apple
2
NULL
3
NULL
After
ID
Name
1
Apple
2
Not Defined
3
Not Defined
I would like to replace NULL with Not Defined.
Sincerely,
knozawa

NULL value could be replaced using the following functions: IFNULL/NVL/COALESCE:
SELECT ID, COALESCE(Name, 'Not Defined') AS Name
FROM tab

Related

How to Filter NULLS Value in 2 Column in google data studio

I want to filters 2 Row that contains Null in each row
It is possible to get rid the Null value in 2 Row or More ?
I want to remove Null value in 2 Row. but let the value Null if in 1 row contains Value.
Thanks for your help.
Target
Existing
Null
Null
Null
Phone A
So the data only like this
Target
Existing
Null
Phone B
Phone B
Phone C
I Tried Filter chart but only work in 1 Column.

How to get the non null value of an item during group by in SQL

I have a dataset where for a single employee the terminated date can be null or non-null as below:
Employee Terminated_Dt
1 NULL
1 2018-04-01
How to capture only the non-null value during group by on Employee to get the correct date?
Can someone please help me with this?
Your question is not clear but I think I can respond:
In this case the where clause remove the null entry from Terminated_Dt column.
But if you wanna to get all employee (id) it's not respond because the employee with only null Terminated_Dt was not showing .. so you have to add some information and excepted output to have answer.
SELECT Employee, MAX(Terminated_Dt) AS 'Max_Terminated_Dt'
FROM #TEMP_EMPLOYEE
WHERE Terminated_Dt IS NOT NULL
GROUP BY Employee

SQL Server - conditionally delete part of a string within a field

I checked both of these:
Delete part of a field in SQL
Deleting part of a string in MYSQL
but they're not quite what I need.
I've unfortunately inherited a table with a field full of comma-separated strings with no regard for format or order. It's ugly. Now I need to get rid of a particular part of a string:
So let's say I have a table as such:
Column1 Column2
1 XRR01,MMEX1,XFR44
2 XRR02,MMEX1
3 MMEX1,GH345,XFR45,CFA34
4 NMM22,MMEX1,XFR44
5 MMEX1
6 XFR55
I want to do an UPDATE to find and delete any instances of MMEX1 from the Column2 field, and keep the other parts intact.
So then I would be left with:
Column1 Column2
1 XRR01,XFR44
2 XRR02
3 GH345,XFR45,CFA34
4 NMM22,XFR44
5 NULL (or blank, doesn't really matter)
6 XFR55
Is this possible?
Here is one way using Replace function
select replace(replace(Column2,',MMEX1',''),'MMEX1,','')
from Yourtable
replace(Column2,',MMEX1','') will remove the string in middle and last
replace(Column2,'MMEX1,','') will remove the string at the start
Note : storing comma sepearated value in a column is always a pain when comes to data processing. Try and change the table structure

Oracle Function - Function for address indicator

I already have an existing view table which consists of 6 columns with address(2 for home address, 2 for office address and 2 for other address which came from different tables). I need to create another column(Address_indicator) in the same view table wherein it will have a value of 1 if the atleast 1 of the 6 columns have a value or 0 if none of the 6 columns have a value. To do this column im planning to create a function for this. Is this possible?
You can select your indicator value using SQL:
select
case
when address_1 is not null
or address_2 is not null
...
or address_6 is not null
then 1
else 0
end address_indicator
from table
If the "view table" you are talking about is a "view" then you can add the case statement to the SQL of the view. No need for a function.

SQL Server 2005 - Check/Validate null values and add to results

Please see below table structure and output required (struggling to right this)
Table: Employees
Structure
EmpID Manager Account Manager
1 Conrad Craig
2 Rob
3 Holly Luke
Output Required (If manager is not null and account manager is not null then Count is 1+1)
EmpdId Count
1 2
2 1
3 2
I'm struggling to write query which can give me above output
So we are checking of null for manager and account manager. And if they are not null then assign value 1 to them and add them up.
Regards
Hi you could do like this:
SELECT EmpId
CASE WHEN Manager IS NOT NULL AND Account Manager IS NULL THEN 1 ELSE 2 END AS Count
FROM TBL

Resources