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
 General SQL Server Forums
 New to SQL Server Programming
 Lookup help (should be easy to solve)

Author  Topic 

ms960
Starting Member

2 Posts

Posted - 2011-08-11 : 11:00:44
I'm trying to build a query that performs a lookup in a reference table.

My main table has a column named event_id that I need to translate to an event code. I have the event_id, and need the event_code.

My lookup table is this:

event_id event_code
-------- ----------
1 1
2 2
3 3
4 4
5 5
6 7
7 10
8 11
9 12
10 6


I am at a loss as to how to build a query to get the event_code, given the event_id. Would very much appreciate some help from the expertise here!

Thanks so much!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-11 : 11:06:48
[code]select event_code
from table
where event_id = @eventid
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-08-11 : 11:14:50
SELECT MainTable.column1, Lookup.Event_Code
FROM MainTable
INNER JOIN Lookup ON MainTable.Event_ID=Lookup.Event_ID
Go to Top of Page

ms960
Starting Member

2 Posts

Posted - 2011-08-11 : 11:57:22
Thanks so much! Took care of it.
Go to Top of Page
   

- Advertisement -