SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Phone number list by location
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jchoudja
Starting Member

USA
41 Posts

Posted - 02/22/2013 :  11:38:29  Show Profile  Reply with Quote
Hi, I am trying to get a phone number list by location for each member.

Member
MemberID|MemberName
--------------------
1_______|_Bean
2_______|_Jonathan
3_______|_Peter
4_______|_Ashley

memberPhone
MemberPhoneID|MemberID|PhoneID
-------------------------------
M1___________|_1______|p1
M2___________|_1______|P2
M3___________|_2______|P3
M4___________|_3______|P4
M5___________|_3______|P5
M6___________|_3______|P6


Phone
PhoneID|PhoneLocationID|PhoneNumber|
-------------------------------
p1_____|_L1____________|_281 520 4444
P2_____|_L3____________|_281 485 6656
P3_____|_L1____________|_713 852 5253
P4_____|_L1____________|_832 525 3333
P5_____|_L3____________|_281 785 5225
P6_____|_L5____________|_281 856 2323


PhoneLocation
PhoneLocationID|PhoneLocationName|PhonelLocationprecedence
L1_____________|CellPhone 1______|_6
L2_____________|CellPhone 2______|_5
L3_____________|Workphone 1______|_3
L4_____________|Workphone 2______|_4
L5_____________|Homephone 1______|_1
L6_____________|Homephone 2______|_2
L7_____________|Otherphone_______|_7

I want to get a table like this: No Duplicate Rows. Each memeber should be in 1 row and all his phone numbers listed in the appropriate colum when thay are available.

MemberPhonelist
MemberID|MemberName|CellPhone_____|HomePhone_____|WorkPhone_____|Otherphone
---------------------------------------------------------------------------
1_______|_Bean_____|_281 520 4444_|______________|_281 485 6656_|__________
2_______|_Jonathan_|_713 852 5253_|______________|______________|__________
3_______|_Peter____|_832 525 3333_|_281 785 5225_|_281 856 2323_|__________
4_______|_Ashley___|______________|______________|______________|__________

I have done someting like this:
CASE WHEN PhoneLocationPrecedence IN (1 , 2) THEN PhonePhoneNumber ELSE '-' END AS homephone
CASE WHEN PhoneLocationPrecedence IN (5 , 6) THEN PhonePhoneNumber ELSE '-' END As Cellphone
CASE WHEN PhoneLocationPrecedence IN (3 , 4) THEN PhonePhoneNumber ELSE '-' END AS workphone
But I am getting only one phone numer per row. If a member has more than 1 it will show phone numbers in many rows

Help please.


jc

jchoudja
Starting Member

USA
41 Posts

Posted - 02/22/2013 :  11:39:43  Show Profile  Reply with Quote
Please read __ in my tables as Blancks


jc
Go to Top of Page

jchoudja
Starting Member

USA
41 Posts

Posted - 02/22/2013 :  11:41:36  Show Profile  Reply with Quote
For now, you can ignore the other Phone location.

jc
Go to Top of Page

Bustaz Kool
Flowing Fount of Yak Knowledge

USA
1645 Posts

Posted - 02/22/2013 :  17:52:05  Show Profile  Reply with Quote
How do you intend multiple phones of the same type (e.g., CellPhone1 and CellPhone2) to be handled in the returned data? Should they be listed in separate columns? Concatenated together in one column? Other? In any event, you might want to make use of the PIVOT operator to transform the vertical list of phone number into a horizontal (single row) list. BOL has details.

=================================================
There are two kinds of light -- the glow that illuminates, and the glare that obscures. -James Thurber
Go to Top of Page

jchoudja
Starting Member

USA
41 Posts

Posted - 02/25/2013 :  07:43:34  Show Profile  Reply with Quote
Phone numebers should be listed in seperate columns like in MemberPhonelist
table above.


jc
Go to Top of Page

jchoudja
Starting Member

USA
41 Posts

Posted - 02/25/2013 :  09:15:26  Show Profile  Reply with Quote
I made is simple here: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=183258
and I don't know how to remove this post.


jc
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000