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 2005 Forums
 Transact-SQL (2005)
 JOIN on different table depending on certain value

Author  Topic 

dazw1
Starting Member

2 Posts

Posted - 2008-10-09 : 07:17:10
Hi,

I have a table which has a column called 'Type', the values that are in the column are either 'Type1' or 'Type2'
what I want is a select statement which JOINS on a different table depending on the value that is in the column 'Type'. soooo something like:

WHERE Type = 'Type1'
LEFT JOIN thistable
WHERE Type = 'Type2'
LEFT JOIN thistable

any help would be great

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-10-09 : 07:45:20
SELECT *
FROM MasterTable AS mt
LEFT JOIN ThisTable AS t1 ON t1.Col1 = mt.Col1 AND mt.Type = '1'
LEFT JOIN ThatTable AS t2 ON t2.Col1 = mt.Col1 AND mt.Type = '2'



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

dazw1
Starting Member

2 Posts

Posted - 2008-10-09 : 08:09:55
awesome thanks very much
Go to Top of Page
   

- Advertisement -