Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have 2 tables
Table1:
EmployeeId    EmployeeName
    12          vivek
    16          siva
    26          prasanth
    34          mahesh

Table2:
Employeeid     Salary
 13             45000
 14             12000
 16             50000
 26             58222

I want the output as follows

Employeeid       Status
  12              N
  16              Y
  26              Y
  34              N


If the employeeid in the table1 is present in the employeeid of table2 list then it should give the output as 'Y' else 'N'

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 24-May-13 21:33pm
v2
Comments
Anurag Sinha V 25-May-13 2:49am    
where are you stuck??
Member 9848727 25-May-13 2:52am    
Im not getting how to achieve the output

@@Anurag Sinha

1 solution

solved your problem..
SQL
select t1.employeeid,case when isnull(t2.salary,0) =0 then 'N' else 'Y' end as 'Status'
from table1 t1 left outer join table2 t2 on t2.employeeid=t1.employeeid
 
Share this answer
 
Comments
Member 9848727 25-May-13 4:07am    
I want the case based on employeeid but not by salary

@@Basmeh Awad
Basmeh Awad 25-May-13 4:28am    
you want to check if salary is available then it will display Y else N so how case will based on employeeid..anyway i show the output as you asked and also you got the idea..now further you can do it by your own

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