I looked around first before posting this and found a lot of questions like this but not the solution I was looking for, this question is different...
I was tasked to normalize an existing database and now I am stuck when writing a view thats to be transparent to the existing database, so I wrote this...
SELECT
Customer.CustomerID, CustomerContact.CustomerContactID,
CustomerPhone.Phone AS "1",
CustomerPhone.Work AS "2",
CustomerPhone.Mobile AS "3",
CustomerPhone.Fax AS "4",
CustomerPhone.Other AS "5",
CustomerSpouse.Spouse AS "6",
CustomerSpouse.SpouseMobile AS "7"
FROM
[Customer]
INNER JOIN
CustomerContact ON Customer.CustomerID = CustomerContact.CustomerID
INNER JOIN
CustomerPhone ON CustomerContact.CustomerContactID = CustomerPhone.CustomerContactID
INNER JOIN
CustomerSpouse ON CustomerContact.CustomerContactID = CustomerSpouse.CustomerContactID
So I made a mistake with the normalization, in the existing database, the CustomerPhone table looks like this
Now I have no idea how to put all the columns into a new column called PhoneType
and show the phone number in another column called PhoneNumber
.
I would rather not have to go back and change the tables from what I already have done, that is a last resort.
I apologize if how I explained it sounds confusing, if it does then please let me know and i'll make an edit and try to explain it better.
Thanks
EDIT Here is the diagram of the tables
Here is what I have being returned with the query that I wrote
So I need every column that has an integer for a header to be placed in a column called PhoneType and its corresponding phone number into a column called PhoneNumber.
What I need to do with my query is making it return this.
PhoneType | PhoneNumber
1 | 123-4567
2 | 234-5678
3 | 345-6789