Click here to Skip to main content
14,982,408 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am not sure if I have missed to search properly, but I couldn't get the exact question as mine

This is something similar but not exact

DETERMINING WHICH TABLE TO JOIN TO

Actually I want to decide with which table to join based on the bases of field value

Kind of

select * from Table1
left join (case when table1.field=1 Then Table2 else Table3 end) final
on Table1.Col1 = final.Col1

Table2 and Table3 has same structure



Here is my table detail,
i had 3 tables employee_master ,employee_timing & designation_timing. now, there is one field in employee master i.e customizedtime. I want to calculate the time of employee on the bases of employee_timing & designation_timing but there is one condition while joining this table if employee_master's field customizedtime is true then i have to join with table employee_timing other wise with designation_timing
Posted
Updated 16-Sep-13 18:24pm
v2
Comments
Maciej Los 16-Sep-13 9:19am
   
Post sample data and expected output...

1 solution

   
Comments
Misha india 17-Sep-13 0:17am
   
this is not relative answer because i want to get output from table field by checking condition in when in above answer they had used procedure but i want to check particular field..
Here is my table detail,


i had 3 tables employee_master ,employee_timing & designation_timing.
now, there is one field in employee master i.e customizedtime.
I want to calculate the time of employee on the bases of employee_timing & designation_timing but there is one condition while joining this table if employee_master's field customizedtime is true then i have to join with table employee_timing other wise with designation_timing
Maciej Los 17-Sep-13 2:40am
   
Do you think we can read in your mind? Post sample data if you want our help.
Misha india 17-Sep-13 3:11am
   
empname day1
Misha present
Tina Absent

this present absent will depend on working hr from either designation_timing & employee timing
Misha india 17-Sep-13 3:19am
   
select empname,case when dt.workinghr >9 then 'present' else 'Absent' end as day1
from employee_detail ed left join designation_timing dt on dt.designationid=ed.designationid and customizedtime=0

this is done for designation wise timing now if customizedtime=1 then i want to join
with employee_timing table
Any body can help me??

Maciej Los 17-Sep-13 3:42am
   
As i had mentioned, improve your question, posting sample data from those 3 tables.
Misha india 17-Sep-13 3:58am
   
employee_detail

id name designationid customizedtime
1 Misha 1 0
2 Tina 2 1


designation_timing
designationid workinghr
1 9


Employee_timing
empid workinghr
2 8

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