Wednesday, July 29, 2015

Print Value if No Result return by query

select coalesce(nullif(salary,-1),4) as c1 from emp;

coalesce - these function work and check data at row level.

It will ceck for each row that if column salary is null then replace value will be replcaed by 4.

Upto here it is fine for me, if any body have question in mind then they can comment on the post.

But My requirement was that if query return no result/ or zero rows then i want to print some default value.
Now as per requirement scenario has been get changed, earlier i was using coalesce function which is working at row level, now i need to control null value at dataset level

see below:
select coalesce(nullif(salary,-1),4) as c1 from emp
union
select '4'  as c1

 

No comments:

Post a Comment

web stats