Click here to Skip to main content
15,915,867 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Here is the thing.I have created two tables called "User" and "Phone".In User table there are two columns "id" and "name".since one user has more than one phone number I've created another table called "Phone" as mentioned above. so phone table contains all the telephone numbers of each user.

User table
id-------name
100-----jack
200-----john


phone table
id-------phone
100-----12345
100-----23456
200-----34567
200-----45678

So now i want to load those two tables to a single grid view as below (Visual studio 2008,C#)

name-----phone
jack-------12345,23456
john-------34567,45678

I wrote a query as
SQL
SELECT U.name,P.phone
FROM tUser U,tPhone P 
WHERE U.id = P.id


But I'm getting the output as below

name-----phone
jack-------12345
jack-------23456
john-------34567
john-------45678

What should I do now? Is it not possible or is there any other way to get the correct output? I'm Waiting for a possitive reply.thanks..
Posted
Updated 24-Sep-11 22:03pm
v2
Comments
rkthiyagarajan 25-Sep-11 4:14am    
Why you use in phone table id=100 twice?
d_lucifer 25-Sep-11 11:13am    
because that user has two phone numbers..
OriginalGriff 25-Sep-11 5:17am    
Richard, is this the question I referred to in Sugs&Bugs? If so, how did you get it open?

1 solution

declare @phoneNumber varchar(1000)
select @phoneNumber = COALESCE(@phoneNumber + ';','') + phone --Column Name
from phone --Table Name

Select @phoneNumber
 
Share this answer
 
Comments
d_lucifer 25-Sep-11 11:14am    
I have posted same question twice.. sorry about that..
thanks for your help.. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900