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 2012 Forums
 Transact-SQL (2012)
 Lookup function help

Author  Topic 

Blessed1978
Yak Posting Veteran

97 Posts

Posted - 2014-11-07 : 19:20:49
I created a lookup table that has ids in one column a names in the next.

Instead of doing a case like statement on my employees table it should look into that lookup table and whereever it sees names in the name field in the employees table it should lookup the name in my lookup table and assign the id associated to it in the id field in my lookup table

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-11-08 : 09:25:48
Select e.stuff, l.name
From employees e
Join lookup l
On e.id = l.id
Go to Top of Page

theboyholty
Posting Yak Master

226 Posts

Posted - 2014-11-17 : 09:57:39
Tiny amendment as the OP indicated he wanted to join on name . .
Select e.stuff, l.id
From employees e
Join lookup l
On e.name = l.name


but basically the same thing and one of the building blocks of T-SQL. You'll really need to understand the principals here if you want to progress.

In any case, surely you already have IDs in your employees table, otherwise how could you tell the difference between two or more employees of the same name? (Its pretty rare, but it happens, especially in larger organisations).

---------------------------------------------------------------------------------
http://www.mannyroadend.co.uk A Bury FC supporters website and forum
Go to Top of Page
   

- Advertisement -