Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Tricky join condition

Author  Topic 

vipinjha123
Starting Member

45 Posts

Posted - 2012-06-01 : 02:13:27
Dear All i am looking for a Employee transfer report
i have 2 table
1-Employee_transfer(empid,from_loc,cuur_loc)here from_loc and curr_loc is the location code and will get location name of this code from location_master table
2-location_master(locid,location_name)
i want to join both table on the basis of locid
and my result output would be like

emp from_loc to_loc

A123 MUMBAI CHENNAI
A458 DELHI GOA

REGARDS,
Vipin jha

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-06-01 : 02:18:24
select
et.empid,
fl.location_name,
cl.location_name
from Employee_transfer et
join location_master fl on fl.locid = et.from_loc
join location_master cl on.cl.locid = et.curr_loc


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-06-01 : 02:20:55
[code]
select *
from Employee_transfer et
inner join location_master lf on et.from_loc = lf.locid
inner join location_master lt on et.to_loc = lt.locid
[/code]



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-06-01 : 02:26:26
kh never sleeps
What is the current time at your location kh?
Here it is 08:26 AM now


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-06-01 : 02:39:24
it is 2:38 PM. I am at GMT+8


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-06-01 : 02:41:35
Haha - you are in the future


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-06-01 : 02:50:56
LOL


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -