Click here to Skip to main content
15,921,837 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Pl find below Code


create table testi3 (empcode varchar(30), payroll_code varchar(30),pprdfrom int,pprdto int)

2. insert values
insert into testi3 values ('1','S0010',90,93)
insert into testi3 values ('1','S0009',93,94)
insert into testi3 values ('1','S0008',94,NULL)
insert into testi3 values ('2','S0008',94,NULL)
insert into testi3 values ('2','S0010',90,93)
insert into testi3 values ('3','S0010',90,93)

3. now if we execute below i get output (1,2)
select * from testi3
where pprdto is null

4. now if we execute below i get output (1,2,3) but i only need 3 since other 1,2 as Null in there previous rows,
select * from testi3
where pprdto is not null


so kindly help with a logic how get only 3
Posted

SQL
select * from testi3 t1
where not exists
(
  select * from testi3 t2 where
   pprdto is null and t1.empcode = t2.empcode
)
 
Share this answer
 
Comments
Kannan 261190 1-Apr-14 11:32am    
Thank you, how exactly write in inner join
Kannan 261190 1-Apr-14 11:38am    
ok i got it , thank you very much
Try
SQL
select * from testi3
where pprdto is not null and emp_code not in (select emp_code from testi3 where pprdto is null)


A neater solution would be to use inner join on the same table instead of using a sub-query.
 
Share this answer
 
Comments
Kannan 261190 1-Apr-14 11:33am    
Thank you, ok i got it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900