Hi I am Working Windows Appl .Net08.
My DB is Access Db.
The below image is from Access DB only.
In the image the table called Contacts having one of the column called 'ContactMedium'. In this Column having values like 'Mobile' , 'email'.
Now i want to saperate these values and create new columns in the same table.
How can make these values as a new columns ??
If i create Crosstab Query it giving error like Value type is not Aggr.
May i know the solution ??
Thanks
Last edited by malatesh kumar; Sep 23rd, 2011 at 03:42 AM.
do you want a permanent solution? or simply a view that represents the data?
medsoft's method will work if you want a permanent solution... but it's a bit heavy handed...
Code:
SELECT C.Title, C.FirstName, C.LastName, C.Street, .... , PHONE.ContactNumber as PhoneNumber, EMAIL.ContactNumber as EmailAddress
FROM tblContacts C
left join tblContacts PHONE on C.ID = PHONE.ID and PHONE.ContactMedium = 'Mobile'
left join tblContacts EMAIL on C.ID = EMAIL.ID and EMAIL.ContactMedium = 'email'
Hi Thanks for given response.
No i dont want Permanent Solution, i want simply view table thats it.
techgnome , as per ur code :
i wrote same code in my Access DB, but i am getting join Error "Syntax error in join Operation"
My Code is as below:
vb Code:
SELECT C.PersonID, C.EventName, C.Surname, C.GivenName, C.InstitutionName, PhysicalAddress.ContactNumber as PA
FROM tblTEMP AS C RIGHT JOIN tblTEMP ON C.PersonID = tblTEMP.PersonID
and PhysicalAddress.ContactMedium= 'Physical Address' ;
secondly, where did "PhysicalAddress" come from? You didn't alias any of the tables as PhysicalAddress... it should be just tblTemp, both in the join and in the select...
Hi i am getting the new columns Successfully..
The image is showing i am getting new columns.
But the problem is the number of rows are increased .
How can i delete the duplicates .
My SQL Query is as Below:
Code:
SELECT C.PersonID, C.EventName, C.Type, C.StartDate, C.EndDate, C.Venue, C.OrganizedBy, C.Surname, C.GivenName, C.Gender, C.Nationality, C.InstitutionName, C.InstitutionType, C.JobStatus,
C.CurrentDesignation, C.Role, [Land-Telephone].ContactNumber AS LPHONE, PhysicalAddress.ContactNumber AS Address, FAX.ContactNumber AS FAX, C.City, C.State, C.Country
FROM ((tblTEMP AS C LEFT JOIN tblTEMP AS [Land-Telephone] ON C.PersonID = [Land-Telephone].[PersonID])
LEFT JOIN tblTEMP AS PhysicalAddress ON C.PersonID = PhysicalAddress.[PersonID])
LEFT JOIN tblTEMP AS FAX ON C.PersonID = FAX.[PersonID]
WHERE ((([Land-Telephone].ContactMedium)='Land-Telephone') AND ((PhysicalAddress.ContactMedium)='PhysicalAddress') AND ((FAX.ContactMedium)='FAX'));
HI Before Distinct Command i got some thousands of rows came but after apply the Distinct i am getting 30 Rows. the rows are reduced but actually my output rows should be 9 only. i want to remove few more duplicate records.
In my Temp Table Some persons having only Physical Address but some having both Physical Address as well as LandPhone and Fax...
So for each personID it displays 2 or more records.
First, PHONE is an alias for the table. Because in the sample, I joined the table to itself, each one has to have a different name...
Secondly, you're getting multiple lines because each contact has multiple rows in the table...
Thirdly, DISTINCT isn't the solution in this case... but will probably suffice given the info at hand, and trying to keep it simple.
Lastly... with out knowing more about the data and the table's design... I don't know what to tell you about eliminating the duplicate rows... other than to ask, does every contact have a physical address line? Your comment about some having only a physical address would suggest that, but your screen shots say otherwise.