SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Concat String of More than 30000 Chars


Concat String of More than 30000 Chars

Author
Message
pankajm
pankajm
Valued Member
Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)

Group: General Forum Members
Points: 57 Visits: 63
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
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (84K reputation)SSC Guru (84K reputation)SSC Guru (84K reputation)SSC Guru (84K reputation)SSC Guru (84K reputation)SSC Guru (84K reputation)SSC Guru (84K reputation)SSC Guru (84K reputation)

Group: General Forum Members
Points: 84753 Visits: 41069
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.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
pankajm
pankajm
Valued Member
Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)

Group: General Forum Members
Points: 57 Visits: 63
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
sgmunson
sgmunson
SSCertifiable
SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)

Group: General Forum Members
Points: 6834 Visits: 4361
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)
SmileSmileSmile

Steve
‌(aka sgmunson)
Smile Smile Smile
Health & Nutrition
pankajm
pankajm
Valued Member
Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)

Group: General Forum Members
Points: 57 Visits: 63
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
sgmunson
sgmunson
SSCertifiable
SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)

Group: General Forum Members
Points: 6834 Visits: 4361
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)
SmileSmileSmile

Steve
‌(aka sgmunson)
Smile Smile Smile
Health & Nutrition
sebastiaan.thompson
sebastiaan.thompson
Grasshopper
Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)

Group: General Forum Members
Points: 18 Visits: 44
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.
Attachments
Search Script Routines V2 1.rar (6 views, 1.00 KB)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search