Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Concatenating during a SELECT
Message
De
14/11/2000 14:47:37
 
 
À
14/11/2000 14:33:49
Elyse Pomerantz
Dynamic Data Concepts, Inc.
Brooklyn, New York, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00441758
Message ID:
00441780
Vues:
12
>>>I'm doing a SELECT on a file and for one of the columns I want a list of the distinct (character) values for that field. Is there any nice way of doing this?
>>>
>>>Thanks,
>>>Elyse
>>
>>How do you want the result to look?
>>
>>If you just want that field do
>>
>>select distinct myfield from mytable into cursor cutmp
>
>No, perhaps I wasn't clear. Let's say I have a table that contains customers and items. I want to group it by customer and end up with a file that contains one record per customer where the second field contains a list of the items for that customer.

>>>I'm doing a SELECT on a file and for one of the columns I want a list of the distinct (character) values for that field. Is there any nice way of doing this?
>>>
>>>Thanks,
>>>Elyse
>>
>>How do you want the result to look?
>>
>>If you just want that field do
>>
>>select distinct myfield from mytable into cursor cutmp
>
>No, perhaps I wasn't clear. Let's say I have a table that contains customers and items. I want to group it by customer and end up with a file that contains one record per customer where the second field contains a list of the items for that customer.



I don't believe this can be done in a single statement.

The second field could end up being longer than C(254), so a memo field is the only option that lets you keep it a single field.

So something like
Use custitem In 0 Order customer
Create Cursor cuCustItems (;
  customer c(FSize("customer","custitem")), ;
  mitems m)

Select Distinct customer ;
  From custitems ;
  Into Cursor cutmp
Select cuCustItems
Append From (DBF("cutmp"))

Set Relation To customer Into custitem 
Scan
  Select custitem
  lcItems = ""
  Scan While customer = cuCustItems
    lcItems = lcItems + Alltrim(custitem.item)+Chr(13)
  EndScan
  Select cuCustItem
  Replace mitems With lcItems
EndScan
Insanity: Doing the same thing over and over and expecting different results.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform