English 中文(简体)
• 在有8 000多个特点时,如何使用印刷品
原标题:how to use print statement when you have more than 8000 characters

我有这样的程序,守则也照此办理:

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.

请允许我知道我究竟是哪里错了?

最佳回答

为什么要印刷?

如果你想看到一切,那么你为什么没有用文字做选择。

Select Convert(xml, @script)

EDIT:

页: 1

PRINT SUBSTRING(@script,@pos,7500)
问题回答

暂无回答




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

难以执行 REGEXP_SUBSTR

I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域

SQL Query Shortcuts

What are some cool SQL shorthands that you know of? For example, something I learned today is you can specify to group by an index: SELECT col1, col2 FROM table GROUP BY 2 This will group by col2

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

Running numbers in SQL

I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0; How can i create a result set with a running number in the first row? So the result would look like this: 1 Name_1 2 ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签