Home Forums Programming XML Parse String By Column Position RE: Parse String By Column Position

  • terrance.steadman (8/6/2015)


    Greetings All,

    Thank you for the current replies. I had a feeling that the way Jeff had said would end up being the primary solution. Still, when running tests with a script, it would have been nice to have a way to keep the test file within the database in a format I could adjust and rip apart as needed.

    I had also thought about using some method to check the files that we create to see if the data is going into the correct columns as necessary. So, basically, being able to convert from a single string into fields and from fields into a single string.

    I guess I was considering how things used to be when memory wasn't protected and variables were nothing more than memory address locations with an expected length. In languages like Assembly, you could define a variable that was 3,000 characters long to hold your single string. Then, define a bunch of variables inside the same memory location. Each one referencing the slice for it's own variable value. This also meant converting from a single string to multiple fields, and vice - versa was rather fast. You just write the one big field and the others were already populated at the same time. You could adjust 1 of the distinct fields and the single line record was adjusted at the same time.

    Aahh. The simplicity of strings in the past (* oops, my age is showing *).

    On a more serious note, I had considered that the FOR XML abilities might have contained the ability to either rip apart, or put together a single string from multiple string fields. Quite possibly with the format file as suggested by Jeff.

    Thank you for your time.

    If you create the right kind of BCP format file, the right kind of staging table, and set BULK INSERT to sequester any errors, you'll have all the things you say. I strong recommend you lookup "BCP Format File" and "BULK INSERT". It's code that works the "old way" (nasty fast, easy to use, always works when setup correctly) but without having to actually write loops.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)