Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
3 Tables Into 1 Text File
Message
 
 
À
27/04/2000 09:35:21
Julie Ball
Gardner Publications, Inc.
Cincinnati, Ohio, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00364076
Message ID:
00364117
Vues:
32
Julie,

I would recomend to rewrite your progam using SQL-SELECT and ? command
***Opening Tables 
SELECT 0
USE N:\apps\imts\imt_addr
SET ORDER TO TAG Compid 
SELECT 0
USE N:\apps\imts\imt_list
SELECT 0
USE N:\apps\imts\cdtxt\comptrad


***  CREATE PRODUCT INDEX BY CATEGORY ***
l_break = SPACE(25)
GO TOP

SCAN FOR imt_addr.ltrrecv <> 'K' AND INLIST(imt_addr.crossid=' ', 'D')
	filename = alltrim(imt_addr.Compid)+'.txt'
	SET PRINTER TO 'n:\apps\imts\cdtxt\compinfo\' + filename
	SET PRINTER ON
	* Address Info
	? ALLTRIM(imt_addr.bthname)
	? ALLTRIM(imt_addr.address1)
	? ALLTRIM(imt_addr.address2)
	? ALLTRIM(imt_addr.city)
	? ALLTRIM(imt_addr.state)
	? ALLTRIM(imt_addr.zip)
	? ALLTRIM(imt_addr.country)	

	lcCompid = imt_addr.Compid
        * Trade names
	SELECT * FROM comptrad WHERE comptrad.Compid = lcCompid INTO CURSOR cr1
	SCAN
		? CHR(9) + ALLTRIM(comptrad.tr_trname)
	ENDSCAN
	
	SELECT imt_addr
	? ALLTRIM(imt_addr.im_multi)

        * Product list
	SELECT imt_list			
	SELECT * FROM imt_list WHERE imt_list.Compid = lcCompid INTO CURSOR cr2
	SCAN
		? CHR(9) + ALLTRIM(imt_list.ls_descrip)
	ENDSCAN
	SET PRINTER TO 
	SELECT imt_addr
ENDSCAN

SET PRINTER TO 
SET PRINTER OFF
>I am trying to create a program that displays 3 related tables into a text file, but I am running into some problems. What is happening, is that the info in table 3 is only displaying the last record and then the Advertiaing info is displaying as many times as there are records in Table2. I know something is wrong with my looping but I haven't had any luck figuring it out for myself.
>
>Here is my criteria:
>Table 1: imt_addr - this table has the company information in it (such as ID, Compy Name, addr, etc.)
>
>Table 2: imt_list - this contains all the products that a company processes. So one company could have multiple records.
>
>Table 3: comptrad - this file contains all the differnet Trad names for a particular company. Again, this file can have mulitple records per company.
>
>All 3 of these tables are related by the company ID. A text file will be created for each company with the following information in this order:
>Company Name (Table1)
>Address Info (Table1)
>List of Trade Names (Table3)
>Advertising info (Table1)
>List of Products (Table2)
>
>Here is my code:
>***Opening Tables and Setting Relationships***
>SELECT 1
>USE N:\apps\imts\imt_addr
>SET ORDER TO TAG Compid OF n:\apps\imts\imt_addr.cdx
>SELECT 2
>USE N:\apps\imts\imt_list
>SET ORDER TO TAG Ls_compid OF N:\apps\imts\imt_list.cdx
>SELECT 3
>USE N:\apps\imts\cdtxt\comptrad
>SET ORDER TO TAG Compid OF N:\apps\imts\cdtxt\comptrad.cdx
>
>SELECT imt_addr
>SET RELATION TO Imt_addr.compid INTO imt_list ADDITIVE
>SET SKIP TO imt_list
>
>SELECT imt_addr
>SET RELATION TO Imt_addr.compid INTO comptrad ADDITIVE
>SET SKIP TO comptrad
>
>*** CREATE PRODUCT INDEX BY CATEGORY ***
>_PEJECT = 'NONE'
>_PLENGTH=32676
>_PLINENO= 1
>l_break = SPACE(25)
>GO TOP
>Save_code = ' '
>SCAN
>IF imt_addr.ltrrecv<>'K'
> IF imt_addr.crossid=' ' OR imt_addr.crosstype='D'
> SELECT imt_list
> IF Save_code != alltrim(imt_addr.Compid)
> filename = alltrim(imt_addr.Compid)+'.txt'
> Save_code = alltrim(imt_addr.Compid)
> SET DEVICE TO FILE 'n:\apps\imts\cdtxt\compinfo\' + filename
> _PLINENO= 1
> SELECT imt_addr
> @_PLINENO,0 SAY ALLTRIM(imt_addr.bthname)+CHR(13)
> @_PLINENO,0 SAY ALLTRIM(imt_addr.address1)+CHR(13)
> @_PLINENO,0 SAY ALLTRIM(imt_addr.address2)+CHR(13)
> @_PLINENO,0 SAY ALLTRIM(imt_addr.city)+CHR(13)
> @_PLINENO,0 SAY ALLTRIM(imt_addr.state)+CHR(13)
> @_PLINENO,0 SAY ALLTRIM(imt_addr.zip)+CHR(13)
> @_PLINENO,0 SAY ALLTRIM(imt_addr.country)+CHR(13)
> SELECT comptrad
> IF comptrad.Compid=imt_addr.Compid
> @_PLINENO,0 SAY ALLTRIM(comptrad.tr_trname)+CHR(9)
> ENDIF
> SELECT imt_addr
> @_PLINENO,0 SAY CHR(13)+ALLTRIM(imt_addr.im_multi)+CHR(13)
> ENDIF
> SELECT imt_list
> IF imt_list.ls_Compid=imt_addr.Compid
> @_PLINENO,0 SAY ALLTRIM(imt_list.ls_descrip)+CHR(9)
> ENDIF
>ENDIF
>ENDIF
>ENDSCAN
>
>_PEJECT = 'AFTER'
>SET DEVICE TO SCREEN
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform