Click here to Skip to main content
15,910,886 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have two tables they are

1) student(student_no (primary Key) ,student_name)
2) phoneDetails(student_no (Foreign Key,phone no)


student table has the records like this

1 raj
2 rani
3 babu

phonedetails table has the records like this

1 3434556
2 4555667
1 4567566
3 5678908
2 5623468
2 1234565


A student can have multiple no of phone numbers,I would like to get these numbers in comma separated values,

I would like to get the result as

1 raj 3434556,4567566
2 rani 4555667,5623468,1234565
3 babu 5678908


Please help me through SQL Server queries.
Posted
Updated 29-Dec-11 18:51pm
v2
Comments
fjdiewornncalwe 30-Dec-11 0:51am    
I would suggest you make some attempt on your own homework first. Try writing the queries based on your lessons. Then, when they don't work, ask a specific question. Show us the code you have attempted to use and we can steer you in the right direction. We don't do your homework for you.
sacraj 30-Dec-11 3:58am    
I have solved this problem by myself. through select stuff()and FOR XML PATH.

1 solution

Your tables 'student' and 'phonedetails' are related with column name

'student_no'. So you can query required information by joining 2 tables. Once you

get the result, do 'string.format' to get the result the way you need.

To join the tables use sql statements 'inner join' or 'join'.
 
Share this answer
 

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