When i run sql query such as;
Select
F1 as name,
F2 as phone
from Table where condition = true
If F2 = 0
i need to that field to be No Phone Number
instead of null
or 0
UPDATE [table] SET [column]=0 WHERE [column] IS NULL; Null Values can be replaced in SQL by using UPDATE, SET, and WHERE to search a column in a table for nulls and replace them. In the example above it replaces them with 0.
To exclude entries with “0”, you need to use NULLIF() with function AVG(). Insert some records in the table using insert command. Display all records from the table using select statement.
SQL pattern matching allows you to search for patterns in data if you don't know the exact word or phrase you are seeking. This kind of SQL query uses wildcard characters to match a pattern, rather than specifying it exactly. For example, you can use the wildcard "C%" to match any string beginning with a capital C.
You can do that with a CASE statement:
SELECT
CASE WHEN F2 = '0' THEN '(No Phone Number)' ELSE F2 END AS Phone
...
SELECT
CASE WHEN F2 = '0' OR F2 IS NULL THEN '(No Phone Number)' ELSE F2 END AS Phone
You will need to use CASE
as;
SELECT
F1 As name,
CASE WHEN F2 IS NULL OR F2 = '0' THEN 'No Phone Number' ELSE F2 END As phone
FROM Table
WHERE condition = 'true'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With