×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Changing Data Types
2

Changing Data Types

Changing Data Types

(OP)
Hi there:
I am trying to bring together 2 completely disparate databases into one. The data is essentially similar but the data types are different; thus 'order number' is an integer in one and text in another.
I am pulling the data from one into a paradox table, ready for import into the other.
Is there any way of programatically changing the data type in the paradox table so as to allow import into the other?
i have thought about exporting to a text file, then bringing into a new table in the propoer format but is there a better way?
Thanks in advance!

RE: Changing Data Types

How about opening a tcursor on each table, the scanning the one table, inserting a record into the other and assigning the values from the one cast to the proper data type into the other.

CODE

tcS.open("sourcetable.db")
tcD.open("destination.db")
tcD.edit()
scan tcS :
  tcD.insertafterrecord()
  tcD."fieldone"=string(tcS."longintfield")
  try
    tcD.unlockrecord()
  onFail
  ; handle errors
  endtry
endscan
tcD.endedit()
tcD.close()
tcS.close()

Tony McGuire
http://www.wjcitycouncil.com
"It's not about having enough time; we have the rest of our lives.  It's about priorities."

RE: Changing Data Types

smartglass,

A way that I would approach it is to get one table to have the same data types as the other by actually programmatically restructuring the data types of the fields.  For example you may wish to either look for text fields and change them to numbers or look for specific named fields and change them to numbers.

I've put a bit of code below and tried to comment it.  Hopefully you get what I am trying to do.  If you get as far as enumerating the field structure then view it and all will become clear.  You will need to substitute your own names where necessary and ensure that no one is using the table etc.

Please let me know if you have any questions.

Regards

Bystander
 

method prep()

Var
 tcFlds      TCursor
 tbl        Table
 dynNewStru      DynArray[] Anytype
EndVar

;=================================================
;Attach your table that you want to change
;and get its field structure
;=================================================

tbl.attach( ":PRIV:your_source_table.DB" )
tbl.enumFieldStruct(":Priv:__field_struct.db")


;==================================================
;open a TCursor to read through the field sturcture
;==================================================

tcFlds.open(":Priv:__field_struct.db" )
tcFlds.edit()


;======================================================
;scan through the field sturcture
;either look for specific fields or field types
;both examples are below and make your changes
;======================================================

Scan tcFlds:

 if   tcFlds."Field Name"= "XXXXX"   then
      tcFlds."Type"= "Number"
      tcFlds."Size"=1
      tcFlds."Dec"=0
 Endif
EndScan

Scan tcFlds:
 if    tcFlds."Type"= "Alpha"    then
       tcFlds."Type"= "Number"
       tcFlds."Size"=1
       tcFlds."Dec"=0
 Endif
EndScan

tcFlds.endEdit()
tcFlds.close()

;====================================================
;replace your source table's field sturcture with the
;revised one
;=====================================================


dynNewStru["FIELDSTRUCT"] = ":Priv:__field_struct.db"
tbl.restructure( dynNewStru )

endmethod

RE: Changing Data Types

(OP)
Thanks to you both for your help.
I have applied both methods - and copying the whole lot out to text and back again.
In the end I have gone foe Bystanders approach; I need two passes to convert a memo field to  anumber but it works just fine.
Thanks again.

RE: Changing Data Types

smartglass,

Good point, I forgot to mention about type casting.  Glad you sorted it out and glad to have been of service.

Regards

Bystander

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close