Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Rhys writes "well i am a novice at sql server 2005...i have a doubt on how to create a query for"List all of the people who have a cell phone number, an office number and a home number in the database."the related tables are People TelephonePeopleID PhoneIDName CategoryAddress under the category comes "office","home" and "cell"how to effectively write a query for this?shall i use multiple join or nested and?"
SwePeso
Patron Saint of Lost Yaks
30421 Posts
Posted - 2006-10-30 : 07:12:19
some sample data would be nice.Peter LarssonHelsingborg, Sweden
khtan
In (Som, Ni, Yak)
17689 Posts
Posted - 2006-10-30 : 07:14:19
This thread does not have title at all ?KH
SwePeso
Patron Saint of Lost Yaks
30421 Posts
Posted - 2006-10-30 : 07:20:14
Something like this maybe?
SELECT p.*FROM People pINNER JOIN ( SELECT PhoneID, SUM(CASE WHEN Category = 'Office' THEN 1 ELSE 0 END) Office, SUM(CASE WHEN Category = 'Home' THEN 1 ELSE 0 END) Home, SUM(CASE WHEN Category = 'Cell' THEN 1 ELSE 0 END) Cell, FROM Telephone GROUP BY PhoneID ) d on d.PhoneID = p.PeopleIDWHERE SIGN(Office) + SIGN(Home) + SIGN(Cell) = 3
Peter LarssonHelsingborg, Sweden
SwePeso
Patron Saint of Lost Yaks
30421 Posts
Posted - 2006-10-30 : 07:34:19
quote:Originally posted by khtan This thread does not have title at all ?
I found the space Peter LarssonHelsingborg, Sweden