I have a process that calls a proc that BCP's a delimited file into a table. Well the SOX police say a header and footer must be added to the file. Needless to say this screws my BCP process.
Does anyone know how to strip a header and footer record from a text file using transact sql or have any other suggestions to strip the records?Well, -F will allow you to bypass the headers... If you can magically devine the number of rows, then -L will allow you to bypass the footers.
If that doesn't suffice, you can always use brute force! Either specify a format file and a batch size of 1 row (really ugly performance), or BCP into a staging table, then only copy the rows of interest from the staging table to the production table.
The other option that will get the job done, but might infuriate the SOX-meisters would be to use the "Flintstone" method... Write one utility to apply the requisite header and footer, and a separate utility to remove the header and footer before using BCP to import the data!
-PatP|||Yeah, well...I'm sure SOX is gonna ask you to interogate thos headers and trailers as well...
bcp the whole damn thing in to a single column table varchar(8000)
Sounds like a mainframe file, so do you have record identifiers?
Like 'H', 'D', and 'T'?|||Yeah, well...I'm sure SOX is gonna ask you to interogate thos headers and trailers as well...Oh! You're no fun!
bcp the whole damn thing in to a single column table varchar(8000)Nothing quite like brute force! 'Tain't pretty, but it does get the job done.
-PatP|||What's funny is they don't care if the header and footer are interogated. I'm lobbying to remove the footer since I can eliminate the header with -F.
My record/row delimiter is {CR}{LF}. I've decided my worse case senario is to add an extra column to the file and BCP the file into a staging table that populates the target table with all records where the new column is null. You know, populate the new column with the header and footer data and leave them blank for all other records. Still too much damn work for such a small problem.|||Let me ask you...what other tool could you possibly need in your toolbox, when GOD made this wonderful thing called a sledge hammer?
Peter,
The Header and trailer thing has always been a pain...
Add an IDENTITY column to get the last and first row...
(OK Pat, release the hounds...)
Do your intergoation and save the stats...
The use a simple bcp, with your first row = 2 and your last row = COUNT(*)
Then perform the audits...
I also like to do an INSERT with parsing to the final destination...but I like what I sketched out above better...
OK, now the discussion about how the data may not get loaded to the table in the same manner that it's in the file...
Take it away Pat...
(did I piss him off too?)|||Nah, it takes LOTS more than that to irrigate me!
I'm actually fine with that idea... The staging table was actually in my first posting, and an identity column makes processing easy. The only thing that might make it a booger to process would be variable length columns with delimiters, although SQL Server can handle that too (at some performance penalty relative to the way that BCP would handle it).
I'm for whatever works, and the less effort needed to get there, the better I like it! I've only got time for so much schtuff, and I really don't want to do any more than I have to!
-PatP
Showing posts with label sox. Show all posts
Showing posts with label sox. Show all posts
Monday, March 12, 2012
Subscribe to:
Posts (Atom)