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 condition with table value

Author  Topic 

gangadhara.ms
Aged Yak Warrior

549 Posts

Posted - 2012-02-14 : 23:35:43
Hi All,

I am doing a left join with 3 tables each having a different category column,in the result set i need to fetch the corresponding category from each table (category is not a column its table level identity).

select A.ID 'Enquiry_ID',A.modified_by 'MI USER ID',U.first_name,u.last_name,a.Product_ID,a.summary,
case when AE.enquiry_ID=A.ID then 'AE'
when PC.enquiry_ID=A.ID then 'PC'
when IR.enquiry_ID=A.ID then 'IR'
when AE.enquiry_ID=A.ID and PC.enquiry_ID=A.ID then ' AE/PC' end as category
from enquiries A
inner join users u on u.ID=A.modified_by
left outer join adverse_events AE on AE.enquiry_ID=A.ID
left outer join dbo.product_complaints PC on PC.enquiry_ID=A.ID
left outer join information_requests IR on IR.enquiry_ID=A.ID
where A.modified_by in (select ID from users where user_group_ID=1)

in the last case statement some of the records are exist in both the table but its not returning in the result set.

pls help

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-15 : 09:37:27
sorry didnt understand the issue you're facing. the query looks syntactically ok. Can you explain with some sample data issue you're facing?

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

Go to Top of Page
   

- Advertisement -