Storing a text file in a VARCHAR(MAX) column

  • I'm using OPENROWSET to put the contents of a text file into a VARCHAR(MAX) column.  However, it is stripping the carriage returns and line feeds out, so when I put the contents of the column back into Notepad I get one long line instead of the original text file.  Is there a way to prevent this?

  • What command are you using to insert the data?

  • We never intended for SQL to be used for text management. You ought to be using the proper tool to store this data. As part Lane put it in one of his humorous essays, "the pumpkin is largely a failure is a shade tree."

    Please post DDL and follow ANSI/ISO standards when asking for help. 

  • Mick Opalak wrote:

    I'm using OPENROWSET to put the contents of a text file into a VARCHAR(MAX) column.  However, it is stripping the carriage returns and line feeds out, so when I put the contents of the column back into Notepad I get one long line instead of the original text file.  Is there a way to prevent this?

    If you're manually copying "from the grid" to NotePad, it's the grid that's removing the CrLf  characters.  Try it with the text output instead of the grid.

    If that doesn't work, then post back and we'll show you some code to check what's stored to see if the CrLfs are actually being stripped by the input process or not.

    --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)

  • if copying from SSMS you can also go to tools->options->Query Results->SQL Server->Results to Grid and tick option "Retail CR/LF on copy or save"

  • jcelko212 32090 wrote:

    We never intended for SQL to be used for text management. You ought to be using the proper tool to store this data. As part Lane put it in one of his humorous essays, "the pumpkin is largely a failure is a shade tree."

    Please share what you consider to be "the proper tool".

    --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)

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

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