Creating a module to import CSV into MS SQL
Posted on 2008-06-26
I have a pre-existing database named waiktrade and table named PRHOURS. The data type of all fields is VARCHAR, and have been created from a CSV exported from Excel. Upon using the "Import Data" function of the SQL Enterprise Manager, I was able to create the table PRHOURS. Here are the fields;
HDRECIDN HDHDRLNK HDWRKDTE HDCOMNUM HDSTRNUM HDSHFNUM HDREGNUM HDEMPNUM HDREGHRS HDOVTHRS HDRECSTS HDRECSRC HDUSRCHG HDDTECHG
What I would like to do is upload ANOTHER CSV file which has current data, then merge it into the pre-existing file in the SQL database. The uploaded file, it sits locally in a folder on the webserver. The name of this file is "upload_prhours.csv" The field/columnames are in the first row.
A condition on merging...both the pre-existing and upload CSV files are the same in struction...the upload_prhours.csv has the most current information, therefore, we have to build this module to query the last record of the pre-existing database and confirm that we don't overlap data. Ideally, to prop the new information in chronological order. HDDTECHG is the date/time and should be used to compare the data.
I need the SQL command to execute in my ASP application.
I"m using ASP and Microsoft SQL Server 2000.