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 2000 Forums
 Transact-SQL (2000)
 Select statement

Author  Topic 

MariaM
Starting Member

17 Posts

Posted - 2002-08-14 : 07:26:34
Hi,

A beginner question:

I have two tables TableA and TableB that looks like this:

TableA

CountryA CountryB
1 1
2 1
3 2

TableB

CountryCode CountryText
1 Sweden
2 Denmark
3 Norway

CountryCode is primary key for TableB. Both the CountryA and CountryB columns are related to the CountryCode in tableB (foreign keys).If I want to create a select statement that prints the CountryText instead of the Codes for the CountryA and CountryB in TableA, how do I do this ? Is it possible or do I have to create two lookup tables ? Thanks in advance !

/Maria

nr
SQLTeam MVY

12543 Posts

Posted - 2002-08-14 : 07:36:21
select CountryA = b1.CountryText, CountryB = b2.CountryText
from TableA a, TableB b1, TableB b2
where a.CountryA = b1.CountryCode
and a.CountryB = b2.CountryCode


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -