--
-- ### Nested case cond check  
-- 
-- 


drop if exists table t1;
create table t1 ( a int , b string(20));

drop if exists table t2;
create table t2 ( a int , b string(20));

-- the logic of the nested case condition is nonsens,
-- just a basic check for the nested statement
 
drop if exists view caseview;
create view caseview as
select

	   case when  ( select count(*) from t2 where t2.a = 1 )  > 1
	   -- case when   t2.a = 1 
	   	then
			case when  t2.b = t1.b
			then
			    'VALID'
		        else
	                    'INVALID'
		        end
		else
		        'VALID'
		end as status,

	t2.b as tb
		
from t1, t2 where t1.a = t2.a;

insert into t1 values ( 1, 'XXXX');
insert into t1 values ( 1, 'XXXX');
insert into t1 values ( 1, 'XXXX');
insert into t1 values ( 1, 'XXXX');
insert into t1 values ( 1, 'XXXX');
insert into t1 values ( 1, 'XXXX');
insert into t2 values ( 1, 'XXXX');
insert into t2 values ( 1, 'XXXX');

select * from caseview;

