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
 SQL Server Development (2000)
 Lookup Keys

Author  Topic 

ahsan19
Starting Member

7 Posts

Posted - 2006-11-10 : 09:57:25
I have two tables:

1. tblCarrier
2. tblUser

The table tblCarrier has a column OwnerId which is being looked up in table tblUser. How can I identify the key that is being used in table tblUser to do this lookup?

Here is what the table looks like:

CREATE TABLE [dbo].[tblusers](
[UserGuid] [uniqueidentifier] NOT NULL,
[LastName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[FirstName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[FullName] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[AccountType] [int] NULL CONSTRAINT [DF_tblUsers_AccountType] DEFAULT ((0)),
[UserType] [varchar](3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
)

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-10 : 10:18:38
select tblusers.*, case when tblcarrier.ownerid is null then 'Is not in use' else 'Is in use' end
from tblusers
left join tblcarrier on tblcarrier.ownerid = tblcarrier.userguid


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -