Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_IHquery

  No additional text.


Syntax


-- Name:
--          sp_IHquery

-- Description:
--          Executes query stored in temp table #hquery
--			against specified linked server

-- Security:
-- 	Internal

-- Returns:
--          Error code

-- Owner:
--          acarter

-- Notes:
--			Requires temp table with following definition:
--				create table #hquery(seq int identity(2,1), cmd nvarchar(4000))


CREATE PROCEDURE sys.sp_IHquery
(
	@linkedserver	sysname
)
AS
BEGIN
	declare @retcode	int,
			@command	varchar(4096),
			@dbname		sysname

	SET NOCOUNT ON

	SELECT	@retcode = 0,
			@dbname  = db_name()

	-- Verify publisher linked server login exists
	EXEC @retcode = sys.sp_IHCheckPublisherLogin @publisher = @linkedserver OUTPUT
	IF @retcode != 0
	BEGIN
		RETURN (@retcode)
	END

	-- Validate #hquery table exists and no invalid entry
	IF object_id('tempdb..#hquery', 'U') IS NULL
	OR EXISTS
	(
		SELECT	*
		FROM	#hquery
		WHERE	seq = 0
	)
	BEGIN
        RAISERROR(8624, 16, -1)
		RETURN 1
	END

	-- Prepare quotes for embedded exec
	UPDATE #hquery
	SET cmd = REPLACE(cmd, '''', '''''')
	
	-- Inject execute wrapper fragments
	SET IDENTITY_INSERT #hquery ON
	INSERT INTO #hquery (seq, cmd) VALUES (1, N'execute (N''')
	SET IDENTITY_INSERT #hquery OFF
	INSERT INTO #hquery (cmd) VALUES (N''') at ' + QUOTENAME(@linkedserver))

	-- Execute query
	EXEC @retcode = sys.sp_IHexecresultset N'SELECT cmd FROM #hquery ORDER BY seq', @dbname

	RETURN @retcode
END

 
Last revision 2008RTM
See also

  sp_MSdrop_replcom (Procedure)
sp_MSrepl_refresh_heterogeneous_publisher (Procedure)
sp_MSrepl_setOraclepackageversion (Procedure)
sp_ORAaddarticle (Procedure)
sp_ORAaddpublisher (Procedure)
sp_ORAChangeTableSpace (Procedure)
sp_ORACheckLoopbackSupport (Procedure)
sp_ORAcompiletriggers (Procedure)
sp_ORAdroparticle (Procedure)
sp_ORAdroppublisher (Procedure)
sp_ORAmarksubscriptionvalidation (Procedure)
sp_ORAposttracertoken (Procedure)
sp_ORArowcount (Procedure)
sp_ORASchemaFilter (Procedure)
sp_ORASetXactBatching (Procedure)
sp_ORAValidateRowFilter (Procedure)
sp_ORAXactSetJob (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