create sql statement on text file?
Hi,
I have a access table, I want to read the record and create a external whatever.SQL file, so I can import to the MySQL server, the file will contain a whole bundle "INSERT statement"
I know how to get the record set from the access table, but just don't know how to write it to the text file with the correct format.
The sample record in the text.SQL file should like something below:
INSERT INTO `table1` VALUES ("","Johnny Knight","ABC Company","Tel: 309-432-3432","USA","50230","343550","106","16","0","0","0","logo.gif","1","0","0","0","","1","","0","","0", "0","1","0");
Thanks!
Re: create sql statement on text file?
Do you know the table name and field names at design time? If so
Code:
'assume the recordset with the Access data is rs
rs.MoveFirst
Open "File.sql" for Output As #1
Do
Print #1, "INSERT INTO "; <table name>; " (<field1 name>, <field2 name>, etc.) VALUES ("; rs.Fields(0).Value; ", "; rs.Fields(1).Value; ", "; etc. ; ");"
rs.MoveNext
Until rs.EOF
Close #1