Concat String of More than 30000 Chars

  • Hi all

    I am facing an issue in SQL 2005 in which I want to print a string of more than 30000 chars and they should be appended to each other.

    The requirement is that, I want to create a script dynamically for the sp which is having 30000 chars.

    I got the result in separate chunks but not able to put them together as the maximum supported datatype is varchar(8000). Not able to use ntext and text as they cannot be used as local variables.

    It would be great if anyone can help me in the same.

    Thanks

  • It doesn't matter if you have a max of 8000 characters for a variable, or not. You cannot print more than 8000 characters in SQL Server in a single unbroken line.

    What is it that you're trying to do? I mean, why does the requirement of printing 30,000 characters as an unbroken string exist for you?

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

  • I want to print a complete stored procedure with its formatting preserved.

    Given Below is the part of the query which I am trying to execute.

    While @@FETCH_STATUS = 0

    Begin

    print @strSPText

    Fetch Next From SpText_Cursor Into @strSPText

    End

    In this when the loop executes then the content i.e. printed comes in the new line. I want it to continue from the same line.

    Is there any method to do so.

    Thanks for the help

  • Two critical questions:

    1.) Exactly what do you mean when you say "print"? That can mean anything from getting text output for copy and paste elsewhere, to actually printing something on a printer.

    2.) Exactly what formatting are you seeking to preserve? If you're referring to the color of the keywords, be aware that with SQL Server 2005 and later, SSMS does exactly that if you merely copy and paste the text from a query window into a rich-text capable editor, such as WordPad or MS Word. I've found that using Landscape orientation is usually best when the ultimate desired result is a printed output from a color capable printer.

    Steve

    (aka smunson)

    :):):)

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

  • By saying print I want to output the text so that I can copy it and paste it somewhere else.

    Regarding preserving formatting just do an exercise of printing an stored procedure containing minimum 30 000 chars. Preserving formatting does not mean that the color of the keywords but it means the word should not be broken in two lines like CON

    VERT. Because it throws error.

    Thanks

    Pankaj

  • Ok, if you want to copy and paste, then why is there a need to do anything using T-SQL? Assuming the desire is something along the lines of printing ALL the sp's in one go, then why not use varchar(MAX) instead of varchar(8000). It requires SQL Server 2005 or above, however. FYI...

    Steve

    (aka smunson)

    :):):)

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

  • From what understand about your problem your only objective is to script the procedure with the output to be printed to text.

    If you don't need to specifically have the output to text, I would suggest just using the following: exec sp_helptext 'sp_name' and copy and paste it from the normal grid results.

    If you need to specifically print to text, have a look at the attached script also using sp_helptext and see if it works for you. I created this script to be able script multiple or single procedures at a time with some added options. The only limitation of this script is that if you have a single line of code in the procedure exceeding 255 characters, it will split the string. As a standard I do not think that this will be an issue, but if it is, I have a solution for that as well, but only if needed.

    If you need a more specific solution I might already have a solution available, but just give this a try first.

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

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