txt file ( 128 bit ) with 8000 characteres

  • I have that file with 8000 characteres in only one line and I need to brake down in pieces of 128 characteres each, positioning

    one under each other creating a new file.

    How do I do that?

    any ideas?

    thanks

  • I think probably makes sense to do this in VB (or your choice of language), for each record, loop through to grab x bytes at a time to build the new file.

    Andy

  • Yes I know that..I can do programming, I'm try to know is If exist any way to do this in a querie statement

  • I may be misunderstanding you.

    Are you saying you have a file and the data is 8000 characters long like so.

    BOB THOMPSON11232 MAIN ST.......02/22/1904

    (....... is data in middle of the ends.)

    And you want to extract this into SQL and peel off 128 characters at a time then export these out to individual files.

    like so

    File 1

    BOB THOMPSON11232 MAIN ST...

    File 2

    ...

    File 3

    ...

    File X

    ...02/22/1904

    If so then create a table with a Single varchar(8000) field and use bcp in

    Then using a static table with 1 field of 128 chracters push each 128 piece into the table in a loop, bcp to your file and truncate the table to push the next peice in.

    If I am wrong then please explain what you are after with examples.

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

  • Not to individual files, but to individual records at the same file, what I need is a Query statment to do that.

    ex:

    Pell off 128 characteres and save it on line1

    another 128 and save it on line 2 and so on at the same file

  • Try something like this...

    CREATE TABLE tempX (

    [vals] [char] (5) NOT NULL

    )

    TRUNCATE TABLE tempX

    DECLARE @test-2 AS VARCHAR(20)

    SET @test-2 = 'This is only a test.'

    WHILE LEN(@test) > 0

    BEGIN

    INSERT INTO tempX (vals) VALUES (LEFT(@test,5))

    SET @test-2 = RIGHT(@test,LEN(@test) - (CASE WHEN LEN(@test) < 5 THEN LEN(@test) ELSE 5 END))

    END

    SELECT * FROM tempX

    EXEC master..xp_cmdshell 'bcp testDb..tempX out C:\test.txt -c'

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply