Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL SELECT Statement - Problem with Field Definition Cha
Message
 
À
09/12/1998 10:34:26
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00165075
Message ID:
00165569
Vues:
11
>>>>I program for an iron foundry. I have a table that has daily data entered into it for the weight of each ladle of molten metal that has been poured in the foundry. Some of the weights are identical. For example, today there may be 2 ladles weighing 1873 lbs each, and 3 ladles weighing 1902 lbs each, etc. For EACH ladle that is poured, a record is entered into the table; so that, for the 2 ladles of 1873 lbs mentioned above, you would have 2 individual records stating a Qty of 1, and a Weight of 1873 lbs.
>>>>
>>>>I am attempting to use an SQL SELECT statement to gather this data, GROUP the identical weights together, add up (COUNT) the quantities for records with identical weights, and then write these records INTO another TABLE. Once these these records are tabulated in this fashion, I then wish to turn around and APPEND these records into a permanent history file called Ladles_d.dbf.
>>>>
>>>>Here's the SQL SELECT statement I'm using...
>>>>
>>>>SELECT prodline, dept, date, year, period, COUNT(ladlesqty), weight FROM LdlInput.dbf WHERE Weight <> 0 GROUP BY Weight ORDER BY Weight INTO TABLE LdlData.dbf
>>>>
>>>>This works beautifully with the following exception...
>>>>
>>>>The field definition for the ladlesqty field (the field on which the COUNT is performed) gets changed in the target LdlData table...
>>>>
>>>>
>>>>Fieldname gets changed from ladelsqty to cnt_ladles
>>>>Width changes from Numeric 6 to Numeric 10
>>>>
>>>>
>>>>When I then try to APPEND FROM LdlData into Ladles_d.dbf, the permanent history file (which has the same structure as the daily entry table, LdlInput.dbf), all the fields come across except for the ladlesqty field.
>>>>
>>>>Obviously, this makes my effort totally useless as I lose the quantity of ladles poured. Any help would be greatly appreciated as I am about to pull my hair out at this point. Thanks, CWH.
>>>
>>>It seems to me, that you actually want to use SUM instead of count:
>>>SELECT prodline, dept, date, year, period, 000000+SUM(ladlesqty) AS ladlesqty, weight FROM LdlInput.dbf WHERE Weight <> 0 GROUP BY Weight ORDER BY Weight INTO TABLE LdlData.dbf
>>>
>>>'000000'-will provide needed field length
>>
>>Edward: Man! Do I appreciate the help. Thanks a lot! Also, I learned something else while working thru this problem... I can use the SQL statement to SELECT...INTO an ARRAY, and then APPEND FROM the ARRAY. This prevents creating another table on disk as well as preventing the field renaming problem. The code I used follows...
>>
>>
>>SELECT LdlInput.prodline, ;	&& Copy records to
>>	LdlInput.dept, ;	&& LdlData Array
>>	LdlInput.date, ;
>>	LdlInput.year, ;
>>	LdlInput.period, ;
>>	SUM(LdlInput.ladlesqty) AS ladlesqty, ;
>>	LdlInput.weight ;
>>	FROM LdlInput ;
>>	WHERE LdlInput.Weight <> 0 ;
>>	GROUP BY LdlInput.Weight ;
>>	ORDER BY LdlInput.Weight ;
>>	INTO ARRAY LdlData
>>		
>>	SELECT Ladles_d	&& APPEND records to Ladles_d.dbf for permanent storage.
>>	APPEND FROM ARRAY LdlData
>>
>>
>
>Ok. Just note, that VFP array is limited by 65K elements, so be careful not to hit this limit. You may also consider to SELECT into cursor, and then append from this cursor to your permanent table.

OK... Thanks for the addl info. ~CWH.
Chuck Henry
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform