Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2003
    Posts
    364

    Unanswered: Importing Data???

    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?

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    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

  3. #3
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    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'?
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Quote Originally Posted by Brett Kaiser
    Yeah, well...I'm sure SOX is gonna ask you to interogate thos headers and trailers as well...
    Oh! You're no fun!
    Quote Originally Posted by Brett Kaiser
    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

  5. #5
    Join Date
    Sep 2003
    Posts
    364
    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.

  6. #6
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    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?)
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  7. #7
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •