Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Is this possible in one or two SQL Select?
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01236995
Message ID:
01237003
Vues:
25
This message has been marked as the solution to the initial question of the thread.
It can be done with SQL Select if you build query dynamicly based on MY_TBL2
CLEAR
CREATE CURSOR my_tbl1 (my_value i)
INSERT INTO my_tbl1 VALUES(1)
INSERT INTO my_tbl1 VALUES(2)
INSERT INTO my_tbl1 VALUES(2)
INSERT INTO my_tbl1 VALUES(1)
INSERT INTO my_tbl1 VALUES(3)
CREATE CURSOR my_tbl2 (my_value i, my_caption C(20))
INSERT INTO my_tbl2 VALUES(1, "Caption 1")
INSERT INTO my_tbl2 VALUES(2, "Caption 2")
INSERT INTO my_tbl2 VALUES(3, "Caption 3")

lcColStr = ""
SELECT my_tbl2 
SCAN
	lcColAlias = CHRTRAN(ALLTRIM(my_caption), SPACE(1), "_")
	lcColExpr  = [IIF(t1.my_value = ] + TRANSFORM(my_value) + [,.T., .F.)]
	lcColStr = lcColStr + [, ] + lcColExpr + [ AS ] + lcColAlias 
ENDSCAN

TEXT TO lcSql TEXTMERGE NOSHOW PRETEXT 15
	SELECT t1.my_value <<lcColStr>>
		FROM my_tbl1 t1 JOIN my_tbl2 t2 ON t1.my_value = t2.my_value
ENDTEXT

&lcSql
>I have two tables (simplified):
>Child Table. MY_TBL1. Has column MY_VALUE, I
>This table has a number of records where MY_VALUE varies.
>Example of MY_TBL1:
>
>MY_VALUE
>1
>2
>2
>1
>3
>
>
>Parent Table. MY_TBL2. This table have two columns, MY_VALUE, and MY_CAPT, C, 20. This table has all possible values for MY_VALUE that the child table MY_TBL1 can have. For example, MY_TBL2 could have the following rows:
>
>MY_VALUE   MY_CAPT
>1          "Caption 1"
>2          "Caption 2"
>3          "Caption 3"
>
>
>I want to select records from MY_TBL1 and at the same time create a column for each different value of MY_VALUE. For example, the resulting cursor would have the following rows:
>
>
>CAPTION_1  CAPTION_2 CAPTION_3
>.T.        .F.       .F.
>.F.        .T.       .F.
>.T.        .T.       .F.
>.T.        .F.       .F.
>.F.        .F.       .T.
>
>
>That is, when a row is selected from MY_TBL1 it should set the value of the column (CAPTION_1, 2, or 3) according to the value of the column MY_VALUE.
>
>Is above possible?
>
>Thank you.
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform