Dave : ASCII Input Files...
Posted in 1996
Topics: Error Codes & Troubleshooting, Connectivity: ESQL/C, 4GL & Embedded SQL, Platform-Specific Issues
}Dave wrote :
}Help!
}
}I have a need to check an ascii input file against several tables,
}if the entries are not in the tables, I need to insert them, then
}move on to the next (fixed length) record in the ascii table.
}
}I am using ESQL/C version 7.11, SE 7.11, and I-SQL 6.02 on a sparc
}station 2 running solaris 2.5.
}
}Basically, a simplified version of the database is like this:
}
}Table_a
}
}code char(5);
}value char(25);
}
}Table_b
}
}code char(5);
}value char(25);
}
}Main_Table
}
}a_code char(5) references table_a.code;
}b_code char(5) references table_b.code;
}mainvalue1 ...
}mainvalue2 ...
}
}etc.
}
}I want to insert values from teh ascii tables only if they do not already
}exist in table_a or table_b respectfully, and to always insert into the
}main_table all the values.
}
}Can anyone send me some sample code to do this?
}
}Thanks!!
}
}Dave
}
Dear Dave ,
I have given a sample code to perform the insertion as you mentioned.
It may solve your problem.
I am unable to make out the nature of the primary key of your main table.
It primary key is a composite key and contains a_code and b_code then
you can check whether that combination is exist or not. If not you can
simply insert into main table.
$ select a_code into $a_code from Table_a where
a_code = $code;
if(sqlca.sqlcode == SQLNOTFOUND )
{
a_code = code;
$ insert into Table_a values ($a_code,...);
....
....
}
$ select b_code into $b_code from Table_b where
b_code = $code;
if(sqlca.sqlcode == SQLNOTFOUND )
{
b_code = code;
$ insert into Table_b values ($b_code,...);
....
....
}
$ insert into main_t values ($a_code,$b_code,...);
Goodluck . Bye.
Peter.