November 7, 2007 at 9:04 pm
I am trying to reference 2 columns that have references to userID numbers.
The colums are secondarycontactID and OwnerID. I have to look up the values in another table called userinfo.
I have defined the query as below. How can I add a second ON statement to map T1.secondaryContactID to T2.tp_Login.
SELECT T1.FullUrl, T3.size AS Size, T1.SecondaryContactID, T2.tp_Login AS PSCO
FROM Sites AS T1 INNER JOIN
UserInfo AS T2 ON T1.OwnerID = T2.tp_ID CROSS JOIN
sysfiles AS T3
WHERE (T3.fileid = 1)
This query works but I need to be able to take the T1.sites.secondaryContactID and look up the value in T2.UserInfo.tp_Login
November 7, 2007 at 9:18 pm
AND
--Jeff Moden
Change is inevitable... Change for the better is not.
November 7, 2007 at 9:40 pm
2 Clarifications please.
I am assuming I put the and here.
SELECT T1.FullUrl, T3.size AS Size, T1.SecondaryContactID, T4.tp_Login, T2.tp_Login AS PSCO, T1.OwnerID
FROM Sites AS T1 INNER JOIN
UserInfo AS T2 ON T1.OwnerID = T2.tp_ID
ANDT1.SecondaryContactID = T2.tp_ID CROSS JOIN
sysfiles AS T3
WHERE (T3.fileid = 1)
But when I run the query it returns nothing now. Also I think I have to assign a T value to the tp_login that is mapped to the T1.secondaryContactID. But I am not sure if I should use T4 or have I already declared it and I am just being dense. Thanks for your help in advance. I am working hard to understand and improve my T-SQL coding Skills.
November 7, 2007 at 10:23 pm
Thanks. Your reply got me thinking about it differently.
The answer turned out to be:
Not an AND but adding INNER JOIN to the Second LINE. LOL.
SELECT T1.FullUrl, T4.size AS Size, T1.SecondaryContactID, T5.tp_Login, T2.tp_Login AS PSCO, T1.OwnerID
FROM Sites AS T1 INNER JOIN
UserInfo AS T2 ON T1.OwnerID = T2.tp_ID INNER JOIN
UserInfo AS T5 ON T1.SecondaryContactID = T5.tp_ID CROSS JOIN
sysfiles AS T4
WHERE (T4.fileid = 1)
November 7, 2007 at 11:14 pm
Glad it worked out, John... I misunderstood thinking that you wanted to add a additional condition to an existing join. And, thanks for the feedback.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply