Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_ORAremotequery

  No additional text.


Syntax



-- Name:
--          sp_ORAremotequery

-- Description:
--          Execute remote Oracle query via OPENQUERY.  Can use an optional temp table.

-- Inputs:
--		@Server				== Name of linked server
--		@SelectColumnList	== Comma seperated list of columns to select from
--		@InsTable			== An optional table can be inserted into
--		@InsColumnList		== Comma separated list of columns to insert into (required if @InsTable is not null)

-- Security:
--          Internal

-- Returns:
--          Success/failure + optional temp table

-- Owner:
--          

CREATE PROCEDURE sys.sp_ORAremotequery
(
	@Server				varchar(128),
	@SelectColumnList	nvarchar(2000) = NULL,
	@InsTable			sysname = NULL,
	@InsColumnList		nvarchar(2000) = NULL
)
AS
BEGIN
	DECLARE @retcode	int
	DECLARE @dbname		sysname

	SET NOCOUNT ON
	
	SELECT @retcode = 0
	SELECT @dbname = db_name()

	-- Verify publisher linked server login exists
	EXEC @retcode = sys.sp_IHCheckPublisherLogin @publisher = @Server 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 in (0, 1)
	)
	BEGIN
        RAISERROR(8624, 16, -1)
		RETURN (1)
	END
	
	IF (@SelectColumnList is NOT NULL and @InsColumnList is NULL) or (@InsColumnList is NOT NULL and @SelectColumnList is NULL)
	BEGIN
		RAISERROR(21619, 16, -1)
		RETURN (1)
	END

	-- Prepare quotes for OPENQUERY
	UPDATE #hquery
	SET cmd = REPLACE(cmd, '''', '''''')

	-- Enable identity insert to inject wrapper queries
	SET IDENTITY_INSERT #hquery ON

	IF @InsTable is NULL
	BEGIN
		INSERT INTO #hquery (seq, cmd)
		VALUES (1, N'SELECT * FROM OPENQUERY(' + QUOTENAME(@Server) + ',''')
	END
	ELSE
	BEGIN
		IF @InsColumnList is NULL
		BEGIN
			INSERT INTO #hquery (seq, cmd)
			VALUES (1, N'INSERT INTO ' + QUOTENAME(@InsTable)
						+ ' SELECT * FROM OPENQUERY (' + QUOTENAME(@Server) + ',''')
		END
		ELSE
		BEGIN
			INSERT INTO #hquery (seq, cmd)
			VALUES (1, N'INSERT INTO '+ QUOTENAME(@InsTable)
							+ ' (' + @InsColumnList + ') SELECT ' + @SelectColumnList + ' FROM OPENQUERY('
							+ QUOTENAME(@Server) + ',''')
		END
	END

	-- Close open query
	SET IDENTITY_INSERT #hquery OFF
	INSERT INTO #hquery (cmd) VALUES (N''')')

	-- 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_getOraclepackageversion (Procedure)
sp_MSrepl_getsubscription_status_hsnapshot (Procedure)
sp_MSrepl_get_Oracle_publisher_metadata (Procedure)
sp_MSrepl_get_Oracle_publisher_table (Procedure)
sp_MSrepl_setOraclepackageversion (Procedure)
sp_ORAaddpublisher (Procedure)
sp_ORAChangeTableSpace (Procedure)
sp_ORACheckAdminPrivileges (Procedure)
sp_ORACheckLoopbackSupport (Procedure)
sp_ORACheckSourceTable (Procedure)
sp_ORAdroppublisher (Procedure)
sp_ORAenumpublishertables (Procedure)
sp_ORAenumtablecolumninfo (Procedure)
sp_ORAgetcolumndata (Procedure)
sp_ORAGetTablespaceInfo (Procedure)
sp_ORAgetversion (Procedure)
sp_ORAhelpXactBatching (Procedure)
sp_ORAhelpXactSetJob (Procedure)
sp_ORASchemaFilter (Procedure)
sp_ORASetXactBatching (Procedure)
sp_ORAValidateRowFilter (Procedure)
sp_ORAverifypublisher (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