Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_MSdumpscripttabletonvarcharmax

  No additional text.


Syntax

-- Name: sp_MSdumpscripttabletonvarcharmax

-- Description: This is a helper procedure for dumping the content of
--              the #scripttest temporary table to a file.

-- Parameter: @nvarcharmaxscript nvarchar(max) output

-- Notes: 1) This procedure assumes that #scripttext is created by the caller
--           and the table contains something interesting to be dumped to
--           the output nvarchar(max) variable.

-- Security: This is an internal system procedure

create procedure sys.sp_MSdumpscripttabletonvarcharmax (
    @nvarcharmaxscript nvarchar(max) output
    )
with recompile
as
begin
    set nocount on
    declare @retcode int,
            @current_script_chunk nvarchar(4000),
            @cursor_allocated bit,
            @cursor_opened bit,
            @chunk_delimiter nvarchar(2),
            @textptr binary(16),
            @buffer nvarchar(4000),
            @bufferlen int
    create table #textworktable (scripttablecontent ntext)
    if @@error<> 0 return 1

    -- Initializations
    select @retcode = 0,
           @cursor_allocated = 0,
           @cursor_opened = 0,
           @chunk_delimiter = N'',
           @buffer = N''

    if @nvarcharmaxscript is null
        set @nvarcharmaxscript = N''

    insert into #textworktable values (@nvarcharmaxscript)

    select @textptr = textptr(scripttablecontent) from #textworktable

    -- Cursor through the #scripttext table and
    -- append each row as a newline to @nvarcharmaxscript
    declare hScript cursor local fast_forward for
        select isnull(line, '') from #scripttext order by line_no asc
    if @@error<>0 begin select @retcode = 1 goto Failure end
    set @cursor_opened = 1

    open hScript
    if @@error<>0 begin select @retcode = 1 goto Failure end
    set @cursor_allocated = 1
    fetch hScript into @current_script_chunk
    while (@@fetch_status<>-1)
    begin

        if datalength(@buffer) + datalength(@chunk_delimiter) <= 8000
        begin
            set @buffer = @buffer + @chunk_delimiter
            if @@error<>0 or @retcode<>0 begin select @retcode = 1 goto Failure end
        end
        else
        begin
            set @bufferlen = datalength(@buffer)
            set @buffer = @buffer + @chunk_delimiter
            if @@error<>0 or @retcode<>0 begin select @retcode = 1 goto Failure end
            updatetext #textworktable.scripttablecontent @textptr NULL NULL @buffer
            if @@error<>0 or @retcode<>0 begin select @retcode = 1 goto Failure end
            set @buffer = right(@chunk_delimiter, (datalength(@chunk_delimiter) - 8000 + @bufferlen)/2)
            if @@error<>0 or @retcode<>0 begin select @retcode = 1 goto Failure end
        end

        if datalength(@buffer) + datalength(@current_script_chunk) <= 8000
        begin
            set @buffer = @buffer + @current_script_chunk
            if @@error<>0 or @retcode<>0 begin select @retcode = 1 goto Failure end
        end
        else
        begin
            set @bufferlen = datalength(@buffer)
            set @buffer = @buffer + @current_script_chunk
            if @@error<>0 or @retcode<>0 begin select @retcode = 1 goto Failure end
            updatetext #textworktable.scripttablecontent @textptr NULL NULL @buffer
            if @@error<>0 or @retcode<>0 begin select @retcode = 1 goto Failure end
            set @buffer = right(@current_script_chunk, (datalength(@current_script_chunk) - 8000 + @bufferlen)/2)
            if @@error<>0 or @retcode<>0 begin select @retcode = 1 goto Failure end
        end

        set @chunk_delimiter = N'
'
        if @@error<>0 or @retcode<>0 begin select @retcode = 1 goto Failure end

        fetch hScript into @current_script_chunk
    end
    if datalength(@buffer) > 0
    begin
        updatetext #textworktable.scripttablecontent @textptr NULL NULL @buffer
        if @@error<>0 or @retcode<>0 begin select @retcode = 1 goto Failure end
    end

    select @nvarcharmaxscript = convert(nvarchar(max), scripttablecontent) from #textworktable

Failure:

    if @cursor_opened = 1
    begin
        close hScript
    end

    if @cursor_allocated = 1
    begin
        deallocate hScript
    end

    drop table #textworktable
    return @retcode
end

 
Last revision 2008RTM
See also

  sp_MSdrop_repltran (Procedure)
sp_MSgeneratenosyncsubscriptionsetupscript (Procedure)
sp_MSscriptpeerconflictdetection_customprocs (Procedure)
       



News

  Query a named instance
Sybase+ASE+silent+install
SQL 2008 R2
Deprecated procedures in SQL2008
Reporting Services item-level role definitions
Create all your missing indexes
Converting datetime field
Start MSSQL Server Profiler at time
Replicating MSSQL Server views
Exploring Microsoft Sharepoint
The OLE DB provider "SQLNCLI10" for linked server indicates.
Mobile solar charger
Oracle to SQL Server replication
Cannot insert the value NULL into column
Undocumented Microsoft SQL Server 2008
VMware
Zoekmachine optimalisatie
SQL Servers hidden objects
FckEditor
Flash in Ajax
De hype die AJAX heet
Barcode scannen
MySQL; Gratis, makkelijk en snel!
PHP
sIFR; de combinatie tussen HTML en Flash