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 2005 Forums
 Transact-SQL (2005)
 Please solve this problem

Author  Topic 

whitebird
Starting Member

12 Posts

Posted - 2008-03-10 : 02:50:23
hi,
i have a two tables like this.
employees table
empid, emp_name, emp_designationid, emp_departid
1 'rex' 1 3
2 'robert' 2 3

strings table
id, name
1 'manager'
2 'lead'
3 'software'

i want a sql query to get the data like this

emp_name, emp_designation , emp_depart
rex manager software
robert lead software




Raghu sunkara.

ranganath
Posting Yak Master

209 Posts

Posted - 2008-03-10 : 03:09:50
Hi,

Try with this

DECLARE @Emp TABLE (Empid int , EName varchar(100), DesId int, DeptId Int)
INSERT INTO @Emp
SELECT 1, 'rex', 1, 3 UNION ALL
SELECT 2, 'robert', 2, 3
SELECT * FROM @Emp

DECLARE @Temp TABLE (id int , name varchar(100))
INSERT INTO @Temp
SELECT 1 ,'manager' UNION ALL
SELECT 2 ,'lead' UNION ALL
SELECT 3 ,'software'
SELECT * FROM @Temp


SELECT Ename, t.name , T1.name
FROM @Emp e
INNER JOIN @Temp T ON T.Id = e.Empid
INNER JOIN @Temp T1 ON T1.Id = e.Deptid
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-03-10 : 03:11:59
[code]SELECT a.emp_name,
emp_designation = b.[name],
emp_depart = c.[name
FROM employees a
INNER JOIN strings b ON a.emp_designationid = b.id
INNER JOIN strings c ON a.emp_departid = c.id[/code]


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

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-03-10 : 03:12:44



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

Go to Top of Page
   

- Advertisement -