Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
ALTER TABLE and INSERT INTO not working
Message
 
To
13/12/2006 04:43:30
Michael Gass
Instructional Software, Inc.
Kirkland, Washington, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01177095
Message ID:
01177098
Views:
8
You will lose decimal points if you have fields like N(14,2). Try:
LPARAMETERS curtable, oldtable
LOCAL old,cur,afieldname,afieldtype,afieldsize,zfieldtoadd

  old = FCOUNT(oldtable)
  cur = FCOUNT(curtable)

  SELECT (curtable)
    = AFIELDS(aMyStruc, (curtable))  && structure array for currentfile
    do while old <= cur 
        old = old + 1
        afieldname  = aMyStruc(old,1)
        afieldtype  = aMyStruc(old,2)
        afieldsize  = aMyStruc(old,3)
        afielddeci  = aMyStruc(old,4)
        IF afielddeci # 0
            zfieldtoadd = afieldname + [ ] + afieldtype + [(] + TRANSFORM(afieldsize) + [,]+TRANSFORM(afielddeci) + [)]
        ELSE
            zfieldtoadd = afieldname + [ ] + afieldtype + [(] + TRANSFORM(afieldsize) + [)]
        ENDIF

        SELECT (oldtable)
        ALTER TABLE (oldtable) ADD COLUMN &zfieldtoadd
    ENDDO

    SELECT (curtable)
    INSERT INTO (curtable) SELECT * FROM (oldtable)
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform