Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 27th, 2008, 03:48 PM
Authorized User
 
Join Date: Mar 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using sp_execute with OpenQuery and Parameters

I'm trying to improve some of the performance issues our queries are having as well as drastically improve the readability of several of the stored procedures. One of the recommended things to do was use sp_executesql instead of coding a query with in one giant (N)VARCHAR with the parameters passed in.

For instance...
Code:
   DECLARE @sSQL VARCHAR(4000),
      @var1 VARCHAR(5)

   SET @var1 = 'Cow'

   SET @sSQL = 'SELECT *
                FROM OPENQUERY(ORASRVR1, ''
                     SELECT ORAFld1,
                            ORAFld2
                     FROM tblORATable o
                     WHERE ORAFld1 = '''' + @var1 + ''''
                        AND ORAFld3 = 4'') O'

   EXEC @sSQL
Instead, I am using the following:
Code:
  DECLARE @sSQL NVARCHAR(4000),
      @var1 VARCHAR(5),
      @ParmList NVARCHAR(50)

   SET @var1 = 'Cow'
   SET @ParmList = '@var1 NVARCHAR'

   SET @sSQL = 'SELECT *
                FROM OPENQUERY(ORASRVR1, ''
                     SELECT ORAFld1,
                            ORAFld2
                     FROM tblORATable o
                     WHERE ORAFld1 = @var1
                        AND ORAFld3 = 4'') O'

   EXEC sp_executesql @sSQL, @ParmList, @var1
When I use the sp_executesql I get an "ORA-00936: missing expression" error.

Is there a way to see what SQL is actually going to execute in this instance so I can attempt to track down what the Oracle server thinks is missing?

Thanks






Similar Threads
Thread Thread Starter Forum Replies Last Post
openquery syntax mpankuj SQL Server 2000 11 March 15th, 2010 01:27 AM
OPENQUERY Problem tsimsha SQL Server 2005 0 October 18th, 2007 06:18 AM
OPENQUERY vs EXECUTE on a linked server? aaqqqa SQL Server 2005 1 May 28th, 2007 06:52 AM
Openquery statements aven SQL Server 2000 2 January 11th, 2006 01:33 AM
openquery gr_chris SQL Server 2000 0 September 16th, 2005 08:35 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.