Information générale
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Hi Marcel.
What about something liek this?
Create cursor Source (ID i, DataType c(10), DataValue c(20))
Insert into Source values (531, "make", "FORD")
Insert into Source values (531, "color", "BLUE")
Insert into Source values (532, "make", "HONDA")
Insert into Source values (532, "color", "RED")
Insert into Source values (533, "color", "ORANGE")
Select DISTINCT ID, ;
(SELECT DataValue from Source where Source.DataType == "make " and Source.ID == MainTable.ID) as Make, ;
(SELECT DataValue from Source where Source.DataType == "color " and Source.ID == MainTable.ID) as Color ;
from Source as Maintable ;
into cursor Result
By using a select to get all of the values of the DataType column and a little macro substitution or ExecScript, you could even make a generic routine that will add new columns if new DataType's appear :-)
Ian Simcock.
>I have a cursor with 3 fields order_key, lup_type, lup_value.
>The data might look as follows:
>531 make FORD
>531 color BLUE
>532 make HONDA
>532 color RED
>533 color ORANGE (person didn't enter a car make)
>534...etc.
>
>These values were already retrieved from a vehicle_info table and a lookup table.
>
>How can I take these values and combine them so that it will have the following layout:
>
>order_key, veh_make, veh_color
>531, FORD, BLUE
>532, HONDA, RED
>533, , ORANGE
>
>I tried a self join but can't get the list to show unique order_key's.
>
>As always, thanks for your excellent help.
>
>Marcel
Précédent
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement