General information
Forum:
Microsoft SQL Server
If you wanted to do it on the server side it would involve some cursors and a table variable
Create a empty table variable with the desired output structure
Create a cursor of all the customers you want in this query
For each customer ..
Select the phone numbers into another cursor
Loop though the phone cursor to form a string and store it into a variable
Select the nicknames for that customer into a cursor
Loop though the nickname cursor and form a string and store it into a variable
Insert into the table variable the custID, the phone string, and nickname string
Then select all the results from the table variable to return it from the stored proc.
HTH
Eric
>I have this problem.
>
>Let's say I have a customer table and I'm joining to a customer_phones table and also to an customer_nicknames table.
>
>Now I want the result to look like this, somehow combining the phone numbers into one field and combining the nicknames into another field, basically one row per customer.
>
>nCus_id: 10
>cPhones: '954-546-5496,954-549-6446'
>cNickNames: 'rico,tommy,rock'
Previous
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only