Reputation: 1
I have table t1(name,phone,adress)
and want to create view vw_1
. I'm looking for the basic logic to be something like:-
create view vw_1 (col1,col2)
as
if(t1.name is null)then
select adress,phone from t1
else
select name,phone from t1
Upvotes: 0
Views: 105
Reputation: 60493
Use the coalesce function (doc is for SQL Server, but it's a classic ANSI operator, and works in all -known by me- DBMS).
create view vw_1 (col1,col2)
as
select coalesce(name, adress), phone
from t1
if you mean "NULL OR EMPTY" then
CREATE VIEW vw_1(col1, col2)
AS
SELECT CASE WHEN COALESCE(name, '') = '' THEN adress else name END,
phone
FROM t1
see sqlFiddle
Upvotes: 2