January 1, 2014 at 8:42 am
I am using SQL 2008 R2. I am importing from Flat Files, and I need to validate 20+ fields in each row to insure they are numeric.
I have created code shown below to validate each field.
UPDATE ValidateTable Set in_value = ''
OUTPUT deleted.*, 'Non Numeric in_value', GETDATE(),@CustomerID INTO ErrorTable
Where ISNUMERIC(in_value) = 0;
Is there a faster way to do this validation besides having 20 separate field tests?
Thanks
Tom
January 1, 2014 at 8:46 am
You could use an errorfile during the import operation to validate your values. Be sure to have an acceptable value for MAXERRORS to avoid the import to fail.
January 1, 2014 at 8:49 am
Hi Luis,
Thanks for your reply. Are you talking about using BCP to import the flat file using the error file option? If not, can you give me more information?
Thanks
Tom
January 1, 2014 at 9:05 am
Yes and no.
All import utilities from SQL Server (bcp, bulk insert, openrowset, SSIS) have options to handle errors. The first 3 have the errorfile and max errors options. SSIS has the error output option to redirect rows to a different destination instead of making the component fail.
The question would be what are you using right now.
January 1, 2014 at 9:14 am
I am using BCP to import the Flat file into a Table with ALL fields set to varchar(255) so there will be no validation errors during loading. Next, I am using a separate T-SQL commands like the one shown above to validate each field. This does work, but I would like for it to be faster.
Perhaps I should use SSIS and compare the speed to what I have now?
Thanks
January 1, 2014 at 11:23 am
tom.sage 70179 (1/1/2014)
...into a Table with ALL fields set to varchar(255) so there will be no validation errors during loading
THAT would be the primary problem. From the sounds of it, you're already importing into a staging table and it would take little time to make to define the columns as the correct datatype that you're expecting. What Luis suggested about MAXERRORS and ERRORFILE is spot on.
Perhaps I should use SSIS and compare the speed to what I have now?
No. SSIS won't be any faster and could be a good bit slower if you continue to import to VARCHAR(255) and then do "datatype checking" separately. Let the table work for you. Define it correctly.
--Jeff Moden
Change is inevitable... Change for the better is not.
January 1, 2014 at 11:56 am
Hi Jeff,
Thanks for the good advice. I will change the "staging table" to have the same field types as the production table. Then I will check for errors from the BCP import.
Thanks
Tom
Viewing 7 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply