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.
| Author |
Topic |
|
whitebird
Starting Member
12 Posts |
Posted - 2008-03-10 : 02:50:23
|
| hi, i have a two tables like this. employees tableempid, emp_name, emp_designationid, emp_departid1 'rex' 1 32 'robert' 2 3 strings tableid, name1 'manager'2 'lead'3 'software'i want a sql query to get the data like thisemp_name, emp_designation , emp_departrex manager softwarerobert lead softwareRaghu 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 @EmpSELECT 1, 'rex', 1, 3 UNION ALL SELECT 2, 'robert', 2, 3SELECT * FROM @EmpDECLARE @Temp TABLE (id int , name varchar(100))INSERT INTO @TempSELECT 1 ,'manager' UNION ALL SELECT 2 ,'lead' UNION ALL SELECT 3 ,'software' SELECT * FROM @TempSELECT Ename, t.name , T1.nameFROM @Emp e INNER JOIN @Temp T ON T.Id = e.EmpidINNER JOIN @Temp T1 ON T1.Id = e.Deptid |
 |
|
|
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.[nameFROM 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] |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-03-10 : 03:12:44
|
 KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|
|
|