Stored procedure for data importing from flat files. Need some tips.
I am currently working on creation of SP to automate the process of importing flat data into SQL Server. I want you to give me some useful advice on the best way how to realise, taking into account things I need: 1. File path and name, delimeter sign, table name as variables. 2. Logging process of importing in one file for every import task (errors and output results like in bcp) 3. Process flat files with different column order 4. Check if data we are trying to import already exists in database (don't replicate) 5. Batch import 6. Error cathing Okay, now my thoughts. I would use either bcp or BULK INSERT. Declare delimeter, source file, table as variables. To identify column order I think we should parse first row with names and use intermediate table from which we then INSERT...SELECT into destination table in the right order. Check if data already EXISTS before importing. Still don't know about logging in one file with timeline. Any other errors that may occur? Any advice would be appreciated. Thank you in advance.