Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Left joins in one row
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00793316
Message ID:
00793538
Vues:
28
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'
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform