Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_execresultset_nvarcharmaxrows

  No additional text.


Syntax
create procedure sys.sp_execresultset_nvarcharmaxrows
(
    @cmd     nvarchar(max),        -- Command that will return a resultset to concat and execute
    @debug    bit = 0                -- Display debug information and resultset query (no exec)
)
as
begin
    set nocount on

    declare    @scriptText     nvarchar(max),
        @maxIndex        bigint,
        @rowIndex        bigint

    declare @q1 nvarchar(max)

    select @q1 = N''
    select @scriptText     = N''

    -- load a local tmp table with the resultset based off of the cmd provided
    -- we also attempt to change the database context before execing the cmd
    declare @MSrepl_exec_script table (orderCol int identity(1,1) primary key clustered, scriptText nvarchar(max))
    if @@error <> 0
    begin
        goto Error
    end

    -- For debugging generated procs. Create the table MSmerge_debug_objects in the current database
    -- create table MSmerge_debug_objects (orderCol int identity(1,1) primary key clustered, scriptText nvarchar(max))
    if object_id('MSmerge_debug_objects', 'U') is not NULL
    begin
       insert into MSmerge_debug_objects(scriptText) exec(@cmd)
	end

    insert into @MSrepl_exec_script(scriptText) exec(@cmd)
    if @@error <> 0
    begin
        goto Error
    end

    -- get the max value inserted in the identity col for
    -- @MSrepl_exec_script table and set the rowIndex = 1
    select @maxIndex = max(orderCol),
            @rowIndex = 1
        from @MSrepl_exec_script

    -- retrieve the current scriptText row
    select @scriptText = isnull(scriptText, N'')
        from @MSrepl_exec_script
        where orderCol = @rowIndex

    while (@rowIndex <= @maxIndex)
    begin

        select @q1 = @q1 + @scriptText + N' '

	    -- increment the row position counter
        select @rowIndex = @rowIndex + 1

        -- retrieve the current scriptText row
        select @scriptText = isnull(scriptText, N'')
            from @MSrepl_exec_script
	        where orderCol = @rowIndex
    end

    if @debug = 0
    begin

		exec(@q1)
		if @@error <> 0
		begin
	        goto Error
	    end
	end
    else
    begin
		-- print out debug info
		
		select '@q1' = datalength(@q1)/2
		
		select @q1
    end

    return 0
Error:
    return 1
end

 
Last revision 2008RTM
See also

  sp_MSaddmergetriggers (Procedure)
sp_MScreateandsetarticleprocs (Procedure)
sp_MSmakeviewproc (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