5

MS Query Analyzer を使用して、テキスト フィールドの内容を出力する必要があります。私はこれを試しました:

select top 1 text from myTable

(ここで、テキストはtextフィールドです)

DECLARE @data VarChar(8000) 
select top 1 @data = text from myTable
PRINT @data

最初のものは最初の 2000 程度の文字のみを印刷し、2 番目のものは最初の 8000 文字のみを印刷します。すべてのテキストを取得する方法はありますか?

ノート:

  • SQL Server 7 で動作する必要があります
4

3 に答える 3

9

MSSQL7でvarchar(MAX)を使用できるとは思わないので、ここにすべてのデータを提供するものがあります(注:私が理解しているのは、データを視覚的に確認したいだけで、配置するつもりはないということです。変数に入れるか、返します)。

したがって、これにより文字列全体が印刷されるため、フィールドの内容を視覚的に確認できます。

DECLARE @limit as int,
        @charLen as int,
        @current as int,
        @chars as varchar(8000)

SET @limit = 8000

SELECT  TOP 1 @charLen = LEN(text)
FROM    myTable

SET @current = 1

WHILE @current < @charLen
BEGIN
    SELECT  TOP 1 @chars = SUBSTRING(text,@current,@limit)
    FROM    myTable
    PRINT @chars

    SET @current = @current + @limit
END
于 2008-10-20T22:54:49.640 に答える
1

しばらく Query Analyzer を使用していませんが、[オプション] ウィンドウの結果ウィンドウに表示される最大文字数を調整できます。MSDNのドキュメントを参照してください。

于 2008-10-20T23:24:24.523 に答える
0

http://shortfastcode.blogspot.com/2011/10/getting-around-sql-server-print-8000.html

このストアド プロシージャを使用します。唯一の欠点は、8000文字ごとに改行が発生することです:(

CREATE PROCEDURE [dbo].[LongPrint]
      @String NVARCHAR(MAX)

AS

/*
Example:

exec LongPrint @string =
'This String
Exists to test
the system.'

*/

/* This procedure is designed to overcome the limitation
in the SQL print command that causes it to truncate strings
longer than 8000 characters (4000 for nvarchar).

It will print the text passed to it in substrings smaller than 4000
characters.  If there are carriage returns (CRs) or new lines (NLs in the text),
it will break up the substrings at the carriage returns and the
printed version will exactly reflect the string passed.

If there are insufficient line breaks in the text, it will
print it out in blocks of 4000 characters with an extra carriage
return at that point.

If it is passed a null value, it will do virtually nothing.

NOTE: This is substantially slower than a simple print, so should only be used
when actually needed.
 */

DECLARE
               @CurrentEnd BIGINT, /* track the length of the next substring */
               @offset tinyint /*tracks the amount of offset needed */

set @string = replace(  replace(@string, char(13) + char(10), char(10))   , char(13), char(10))

WHILE LEN(@String) > 1
BEGIN

IF CHARINDEX(CHAR(10), @String) between 1 AND 4000
    BEGIN

SET @CurrentEnd =  CHARINDEX(char(10), @String) -1
           set @offset = 2
    END
    ELSE
    BEGIN
           SET @CurrentEnd = 4000
            set @offset = 1
    END

PRINT SUBSTRING(@String, 1, @CurrentEnd)

set @string = SUBSTRING(@String, @CurrentEnd+@offset, 1073741822)

END /*End While loop*/

これは、もともとhttp://www.sqlservercentral.com/scripts/Print/63240/の SQLServerCentral.com に投稿されたものです。

于 2011-10-20T10:15:00.400 に答える