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)
 SQL help needed!

Author  Topic 

padsp
Starting Member

21 Posts

Posted - 2005-06-30 : 14:50:55
Hi everyone,

I need your help. Here are my problem.

1. I have 3 tables(below table structure with sample data).
TABLE A
contact_id Name
100 Sal Ferrulo
101 Dianne Deppen
TABLE B
estab_id contact_id type_id
1 100 1
1 100 2
2 100 3
2 100 4
2 101 1
2 101 2
TABLE C
estab_id estab_name
1 ABC Restaurant
2 XYZ Hotel

I am looking for the following output to display in ASP.NET.

Contact_id Name Work Place #of work place
100 Sal Ferrulo ABC Restaurant 2
XYZ Hotel
101 Diane Deppen XYZ Hotel 1

I need your help and support.

Thanks
BOB

Kristen
Test

22859 Posts

Posted - 2005-07-01 : 01:30:58
Something like

SELECT A.contact_id, A.Name, A.estab_name, COUNT(*) AS [#of work place]
FROM TABLE_A A
JOIN TABLE_B B
ON B.contact_id = A.contact_id
JOIN TABLE_C C
ON C.estab_id = B.estab_id
GROUP BY A.contact_id, A.Name, A.estab_name
ORDER BY A.contact_id, A.Name, A.estab_name

Kristen
Go to Top of Page
   

- Advertisement -