|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Tuesday, January 10, 2012 8:34 AM
Points: 8,
Visits: 23
|
|
I'm running into the same problems with OPENQUERY. Not being able to provide it with a string argument containing a dynamically created query is just brain-dead as far as I can see. I, too would like to see the rationale for this.
Building up the entire SQL server SQL statement is fine if you simply want to display the output of a query but I need to be able to set variables in a stored procedure or trigger with values abstracted from an Oracle database for further use, but variables set inside an sp_executesql call are localised. Thus
ALTER PROCEDURE SR_numinput @SR_num VARCHAR(20), @cust Varchar(50) OUTPUT, @proj varchar(20) OUTPUT AS BEGIN declare @query NVARCHAR(500); set @query = 'select @cust = NAME, @proj = PROJ_NUM FROM openquery(AtlasTest, ''Select P.NAME,P.PROJ_NUM from SXXX.S_SRV_REQ S, SXXX.S_PROJ P where p.row_id=s.proj_id and s.sr_num='''''+@SR_Num + ''''' '')'; --select @query; execute sp_executesql @query; select @cust as oCustomer, @proj as oProject; END
puts out a msg states that @cust must be declared when the statement is executed, and @cust declared in the procedure itself does not get set.
Any workarounds gratefully received - Thanks Giles
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Tuesday, January 10, 2012 8:34 AM
Points: 8,
Visits: 23
|
|
Got it - using some of the hints earlier in the thread:
ALTER PROCEDURE SR_numinput @SR_number VARCHAR(20), @customer VARCHAR(50) OUTPUT, @project VARCHAR(20) OUTPUT AS BEGIN declare @query NVARCHAR(500); declare @parm NVARCHAR(500); set @parm = N'@cust VARCHAR(50) OUTPUT, @proj VARCHAR(50) OUTPUT';
set @query = 'select @cust = NAME, @proj = PROJ_NUM FROM openquery(AtlasTest, ''Select P.NAME,P.PROJ_NUM from SXXX.S_SRV_REQ S, SXXX.S_PROJ P where p.row_id=s.proj_id and s.sr_num='''''+@SR_Number + ''''' '')'; select @query; execute sp_executesql @query, @parm, @Cust = @customer OUTPUT, @Proj = @project OUTPUT; select @customer as oCustomer, @project as oProject; END
Build up the select string with the input values included. Then use sp_executesql with defining the OUTPUT variables required, and map them to the procedure/trigger variables in the call.
Kind of ugly, but there it is.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Wednesday, June 15, 2011 1:56 PM
Points: 3,
Visits: 6
|
|
Did you ever resolve this issue?
Ken Pearson
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Tuesday, January 10, 2012 8:34 AM
Points: 8,
Visits: 23
|
|
| My second post showed how I got around the problem - it offends my aesthetic sensibilities but that's TSQL for you.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, October 28, 2010 7:10 PM
Points: 2,
Visits: 13
|
|
You proposed a work-around for using select openquery but not when using insert openquery. I'd appreciate if you could suggest a work around when inserting into a timestamp column from SQL server using Oracle Linked Server. Here is my syntax:
insert OPENQUERY(OracleLinkedServer, 'SELECT [Other Columns], TimeStampColumn FROM OracleSchema.OracleTable') select @data, CONVERT(datetime2(7),'2007-05-02T19:58:47.1234567')
TimeStampColumn in Oracle has a datatype of TIMESTAMP(6). I tried all the following to insert timestamps in Oracle but I get the same error in all cases:
Error: OLE DB provider "MSDAORA" for linked server "" returned message "Oracle error occurred, but error message could not be retrieved from Oracle.". OLE DB provider "MSDAORA" for linked server "" returned message "Data type is not supported.". Msg 7321, Level 16, State 2, Line 5 An error occurred while preparing the query "" for execution against OLE DB provider "MSDAORA" for linked server "".
|
|
|
|