Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6736441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:07:48+00:00 2026-05-26T11:07:48+00:00

I have a procedure and the code looks like this: ALTER PROCEDURE [dbo].[usp_Gen_Proc] (@ID

  • 0

I have a procedure and the code looks like this:

ALTER PROCEDURE [dbo].[usp_Gen_Proc] 
(@ID INT )
AS
Begin

IF OBJECT_ID('tempdb..#procedure') IS NOT NULL
DROP TABLE #procedure

DECLARE @Name VARCHAR(100) 
DECLARE @SQL VARCHAR(MAX)
DECLARE @Script VARCHAR(MAX),
@DB VARCHAR(100),
@Schema VARCHAR(100),
@Proc_Name VARCHAR(max),
@BR CHAR(2)

SET @BR = CHAR(10)+ CHAR(13)

SET NOCOUNT ON 

SELECT @Name= [Procedure_Name] FROM dbo.datsource 
WHERE [ID] = @ID

SELECT  @Proc_Name = PARSENAME(@Name, 1) ,
        @Schema = PARSENAME(@Name, 2) ,
        @DB = PARSENAME(@Name, 3)


CREATE TABLE #procedure ( script VARCHAR(MAX) )

EXEC('INSERT INTO #procedure(script)
SELECT definition FROM '+@DB+'.sys.all_sql_modules sq
WHERE sq.object_id = (SELECT object_id FROM '+@DB+'.sys.objects
WHERE type = ''P'' AND name = '''+@Proc_Name+''' ) ')


SET @Script = ' Use ' +@BR  +@DB + @BR+ '  Go' +@BR

SELECT  @Script = @Script+script
FROM    #procedure


DECLARE @pos INT =7500

SELECT  @pos=CHARINDEX(CHAR(13)+CHAR(10),@script,@pos)

PRINT SUBSTRING(@Script,1,@Pos)

DECLARE @Counter INT
SET @Counter = 0
DECLARE @TotalPrints INT
SET @TotalPrints = ( LEN(@script) / 8000 ) 
WHILE @Counter < @TotalPrints 
    BEGIN   

        SET @Counter = @Counter + 1

        PRINT SUBSTRING(@script,@pos+1,7500)
        SET @pos = @pos+7500

        SELECT  @pos=CHARINDEX(CHAR(13)+CHAR(10),@script,@pos)

    END 
END

Basically what the procedure is doing it just prints the procedure code. But the problem I am facing is when I am printing it i am loosing some characters in between.

Can anyone let me know where I am going wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:07:48+00:00Added an answer on May 26, 2026 at 11:07 am

    Why do you want to print ?

    Why you don’t do a select with the script, put it in xml if you want to see everything.

    Select Convert(xml, @script)
    

    EDIT :

    between you don’t need to do +1

    PRINT SUBSTRING(@script,@pos,7500)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have inherited code that looks like this: Stored Procedure UpdateSomeStuff Update Table1 Set
I have Delphi 2007 code that looks like this: procedure WriteString(Stream: TFileStream; var SourceBuffer:
I have a stored procedure that looks something like: CREATE PROCEDURE my_procedure @val_1 INT,
I have a piece of code that looks something like this (ClearImportTable and InsertPage
I have created the following stored procedure.. CREATE PROCEDURE [dbo].[UDSPRBHPRIMBUSTYPESTARTUP] ( @CODE CHAR(5) ,
I have stored procedure: ALTER PROCEDURE [dbo].[k_ShoppingCart_DELETE] @cartGUID nvarchar AS DELETE FROM [dbo].[k_ShoppingCart] WHERE
I have a method that looks like this: try { doStuff(); } catch (Exception
I have the following code within a stored procedure. WHERE WPP.ACCEPTED = 1 AND
I have a block of code that is repeated within a DB2 stored procedure.
Have been fighting this for two days and am very frustrated but feel like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.