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)
 How do I create a Lookup table in SQL?

Author  Topic 

BigSexy
Starting Member

2 Posts

Posted - 2008-05-12 : 13:49:33


Table 1
Skill_ID SkillName
1 xml
2 oracle
3 sql
4 vb

Table 2
EMP_NAME SKILL_ID_1 SKILL_ID_2 SKILL_ID_3
JOHN DOE 1 4 null
JANE COLE 3 4 null
SAM COOK 1 2 4


I want to return the following:

RETURN DATA
EMP SKILL_ID_1 SNAME1 SKILL_ID2 SNAME2
JOHN DOE 1 xml 4 vb
JANE COLE 3 sql 4 vb
SAM COOK 2 oracle 3 sql

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-12 : 13:53:34
[code]SELECT t2.EMP_NAME AS EMP,
t2.SKILL_ID_1,t1.SkillName AS SNAME1,
t2.SKILL_ID_2,t3.SkillName AS SNAME2,
t2.SKILL_ID_3,t4.SkillName AS SNAME3
FROM Table2 t2
LEFT JOIN Table1 t1
ON t1.Skill_ID=t2.SKILL_ID_1
LEFT JOIN Table1 t3
ON t3.Skill_ID=t2.SKILL_ID_2
LEFT JOIN Table1 t4
ON t4.Skill_ID=t2.SKILL_ID_3[/code]
Go to Top of Page
   

- Advertisement -