473,471 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

One subscriver, multiple phone numbers.

1 New Member
Hi,

I dont know if it's gonna be as tough for you guys as it is for me to find the right solution.

Context :

I have 3 tables, abonnement (means subscriber), LnkComClient (which contains the communication values associated with abonnement) and of course
TypeCom (which represents the types of communication : email, fax, cellphone, toll-free number)

I designed my tables this way so I can have as many type of communication possible as I want and also be ready if new ones appear in the future and for each of these type I could have as many entries as I want. Let's say I could have 5 email adresses,3 phones numbers, 3 website urls, etc... all that for 1 abonnement (subscriber).

Here is my current query which is fast but return only the max value for each type of communication which is totally against my design. The query itself is not enough dynamic, if new type of communication appears, it fails to achieve what I want but for dynamic side but it's not a show stopper for me, it's more that it wont returns all the possibilities.

SELECT IdAbonnement,[Courriel],[SiteWeb],[TEL],[CELL],[S.F.],[FAX] FROM (SELECT IdAbonnement,TypeCom.Nom,Valeur FROM Abonnement a LEFT JOIN LnkComClient lnk ON lnk.AbonnementId=a.IdAbonnement INNER JOIN TypeCom ON TypeCom.IdTypeCom=lnk.TypeComId) AS Src PIVOT (
MAX(Valeur)
FOR Nom IN ([Courriel],[SiteWeb],[TEL],[CELL],[S.F.],[FAX])
) pvt
ORDER BY idAbonnement

I also tried that which call a function which return all the emails in one column in a csv style. The performance is really not there when you have 25000 abonnement (subscriber) which has many emails, phone, etc... as they want :

SELECT IdAbonnement,ISNULL(dbo.GetAllEmailForAbonnementId (IdAbonnement),'') AS Email,ISNULL(dbo.GetAllTelForAbonnementId(IdAbonne ment),'') FROM Abonnement

Here is the code for the function GetAllEmailForAbonnementId :

CREATE FUNCTION [dbo].[GetAllEmailForAbonnementId]
(
-- Add the parameters for the function here
@AbonnementId Int
)
RETURNS varchar(2000)
AS
BEGIN
-- Declare the return variable here
DECLARE @LstValeur varchar(2000)

-- Add the T-SQL statements to compute the return value here
SELECT @LstValeur=COALESCE(@LstValeur + ', ', '') + Valeur FROM LnkComClient Lnk WHERE Lnk.AbonnementId=@AbonnementId AND TypeComId=1

-- Return the result of the function
RETURN @LstValeur

END

If you need more information just reply.

Here are my tables if you want to give it a shot.
-- simplified version
CREATE TABLE [dbo].[Abonnement](
[IdAbonnement] [bigint] IDENTITY(1,1) NOT NULL,
[Nom] [varchar](150) COLLATE SQL_Latin1_General_CP1_CI_AS )
GO

CREATE TABLE [dbo].[LnkComClient](
[IdLnkComClient] [bigint] IDENTITY(1,1) NOT NULL,
[AbonnementId] [bigint] NOT NULL,
[TypeComId] [int] NULL,
[Valeur] [varchar](250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
CONSTRAINT [PK_LnkComClient] PRIMARY KEY CLUSTERED
(
[IdLnkComClient] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

CREATE TABLE [dbo].[TypeCom](
[IdTypeCom] [int] IDENTITY(1,1) NOT NULL,
[Nom] [varchar](150) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[IsNumeroTel] [bit] NOT NULL CONSTRAINT [DF_TypeCom_IsNumeroTel] DEFAULT ((0)),
[Weight] [int] NOT NULL CONSTRAINT [DF_TypeCom_Weight] DEFAULT ((0)),
CONSTRAINT [PK_TypeCom] PRIMARY KEY CLUSTERED
(
[IdTypeCom] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

---
Jan 30 '08 #1
0 781

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: joemono | last post by:
Hello everyone! First, I appologize if this posting isn't proper "netiquette" for this group. I've been working with perl for almost 2 years now. However, my regular expression knowledge is...
0
by: misscrf | last post by:
I am currently working on a database, in 3rd normal form, which is for candidates who apply for a job with the law firm that I workd for. My issue is with good form design. I have a main...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
4
by: Brian Henry | last post by:
I have phone numbers like this in a data table 123-435-1234 1231231234 432.234.2321 they all have different formatting, what I want to do is get them all formatted like this (123) 123-1234
2
by: Howard | last post by:
how would you design a table that allows an item to belong to multiple parent categories. single parent example: select * from table1 where parentid = 5 in this case parentid is an indexable...
10
by: JackM | last post by:
I'm still working on validating the phone numbers that are entered on a form but have come across a problem I don't understand how to fix. I can handle most instances when it's in regular US...
5
by: lim4801 | last post by:
I am currently in doing a program which is given by my tutor: Contemplate that you are working for the phone company and want to sell "special" phone numbers to companies. These phone numbers are...
4
by: Blue Streak | last post by:
Hello, Folks! Does anyone know of a website that lists the local phone number formats for each country? TIA...
7
by: Propoflady | last post by:
My contacts can have as many as five or six phone numbers - is it possible to make a query that puts the name, and each phone number after it on the same line - for this reason I have two tables -...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.