Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Concat String of More than 30000 Chars Expand / Collapse
Author
Message
Posted Saturday, September 27, 2008 1:34 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, August 28, 2012 1:26 AM
Points: 53, Visits: 62
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
Post #577274
Posted Saturday, September 27, 2008 5:29 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 4:24 PM
Points: 36,995, Visits: 31,522
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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #577344
Posted Sunday, September 28, 2008 10:02 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, August 28, 2012 1:26 AM
Points: 53, Visits: 62
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

Post #577515
Posted Tuesday, September 30, 2008 8:19 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Yesterday @ 8:03 PM
Points: 1,669, Visits: 2,213
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)

Internet ATM Machine
Post #578341
Posted Tuesday, September 30, 2008 10:10 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, August 28, 2012 1:26 AM
Points: 53, Visits: 62
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
Post #578830
Posted Wednesday, October 1, 2008 6:33 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Yesterday @ 8:03 PM
Points: 1,669, Visits: 2,213
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)

Internet ATM Machine
Post #579006
Posted Friday, April 26, 2013 3:39 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, July 25, 2014 3:28 AM
Points: 16, Visits: 34
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.


  Post Attachments 
Search Script Routines V2 1.rar (2 views, 1.23 KB)
Post #1446874
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse