I am getting data in text file with header rows (having column name) with column delimiter as | , now before loading the file I need to check that the column name of the flat file matches the destination table. How can I do that in script task?
1 Answers
It would be helpful to know why you want to do this. If your aim is to avoid import errors by checking that the file is correctly formatted before importing it, then you might consider the alternative approach of just trying to load it and catching any errors.
That is a useful strategy in many contexts anyway, because up-front checks won't help if you get an error for an unexpected reason, but catching and logging errors in an appropriate way will help you handle error scenarios you hadn't considered. Another reason - that may not apply in this case - is that it's always possible that something changes between the check succeeding and the next step in your package or program running. Which approach makes more sense in each case depends on your overall program logic, programming language etc. This has been discussed on SO before.
But if you do indeed need to do this check up front, you can break down the task into several smaller ones: get the column names from the file; get them from the table; compare them etc. You will probably get more useful answers if you try to work on these smaller steps and ask more specific questions with code, errors etc. if you run into problems.