Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can we simplify this?
Message
 
 
To
10/01/2003 08:36:41
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00740222
Message ID:
00740237
Views:
21
Instead of doing select for each selected code, you can create cursor, store all selected codes into it and use it in your select. Replace nnn with the size of 'siccode2' field in your table.
CREATE CURSOR crsList ( siccode2 C(nnn) )
FOR i = 1 TO THISForm.list3.ListCount
	INSERT INTO crsList VALUES ( alltrim((THISform.list3.List(i))))
ENDFOR

SELECT agbrands.brandname, agclients.clientname, ;
		alltrim(Agind.prefix) As prefix, alltrim(Agind.fname) As Firstname, ;
		alltrim(Agind.initial) as Initial, alltrim(Agind.sname) as Surname, ;
		alltrim(Agind.position) as position, Agind.phone as phone, ;
		Agind.fax as fax, Agind.email as email, ;
		agencies.agname as Agencyname, IIF(agencies.mediaco = .T.,'M','A'), ;
		agencies.agadd1 as Address1, agencies.agadd2 as Address2, ;
		agencies.agadd3 as Address3, agencies.agadd4 as Address4, ;
		alltrim(agencies.county) As county, alltrim(postcode) as postcode ;
	FROM agencies ;
	INNER JOIN Agind ON agencies.agencyid = Agind.agencyid ;
	INNER JOIN indvcl ON Agind.agindid = indvcl.agindid ;
	INNER JOIN agbrands ON agbrands.brandid = indvcl.brandid ;
	INNER JOIN agclients ON agbrands.clientid = agclients.clientid ;
	WHERE Agbrands.siccode2 IN ( ;
		SELECT siccode2 FROM crsList ) ;
	INTO CURSOR temp
I would also recomend to remove all ALLTRIM() functions from your select because they could cause unexpected field truncation. They also useless because the size of the fields in VFP table/cursor is fixed.


>I have a code snippet, which seems very inefficient. I am fairly new to FoxPro. As you will see in the snippet below data is read from a number of tables using joins and then a filter, selected from a list box is applied. This list box can contain thousands of brandtypes(Agbrands.siccode2), from which the user can select (this needs to be so).
>
>When I first tried it using a straight Select SQL Statement into a table, I would get an errortelling me that the SQL statement was too complex. As you can see I now use an array and populate the temp table on record at a time.
>
>Can anyone offer a more efficient method (by the way, it works well and some would say if its not broken, don't fix it, but I am tryingto increase my knowledge of FoxPro.
>
>**CODE SNIPPET
>
< Snip >
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform