Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Append From ... SDF ???
Message
From
05/09/2002 22:10:47
 
 
To
05/09/2002 15:35:05
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00697227
Message ID:
00697336
Views:
14
>Hello all,
>
>Is there a way to append from SDF file such that numeric data with an 'implied' decimal can be imported properly.
>
>Currently I am having to import to a cursor with the field defined as character with correct length. Then, I append that to a cursor with the field set to numeric length+2,2. Then, I do a replace ALL field * .01.
>
>So, this is three passes through the same data.
>
>There's got to be a better way!
>
>BOb

Hi Bob,

You can do it all within one table but it still takes two steps. The approach I like to use is to define extra fields on the end of the DBF I'm importing into, beyond the ones that are needed to correspond to fields in the SDF import file. The extra fields will simply remain empty after the APPEND, then you can do a quick REPLACE ALL (or a SCAN with a REPLACE for each field if there's more than one field to convert) and fill in the desired values.

For example, assume an SDF file with a 3-byte alpha field followed by a 3-byte numeric field with an implied two decimal positions, like this:
ABC123
DEF456
GHI789
Your import code would look like this:
CREATE TABLE myTable ( cField1 c(3), cField2 c(3), nField3 n(10,2))
APPEND FROM myfile.txt TYPE sdf
REPLACE ALL nField3 WITH VAL( cField2) / 100
The values in nField3 will then be 1.23, 4.56, and 7.89 as desired.

HTH,

-Rick
Rick Borup, MCSD

recursion (rE-kur'-shun) n.
  see recursion.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform