?
Solved

Proper syntax for TSQL openquery statement

Posted on 2007-11-14
4
Medium Priority
?
1,183 Views
Last Modified: 2012-08-13
From SQL Server 2005, I am able to query a linked Oracle 10g database with this:
select * from openquery(dgo1,'select * from DGOUSER.HOUSEHOLD')

I'm trying to add a where clause
select * from openquery(dgtest,'select * from dgtable.house where upper(LAST_NAME) = 'SMITH' ')

The error I get is:
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'SMITH'.

What do I have to correct to get the query to work?
0
Comment
Question by:brooksmato
  • 2
  • 2
4 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 20283339
this will do better:
select * from openquery(dgtest,'select * from dgtable.house where upper(LAST_NAME) = ''SMITH'' ')
0
 

Author Comment

by:brooksmato
ID: 20283418
angellll, running your query:
select * from openquery(dgtest,'select * from dgtable.house where upper(LAST_NAME) = ''SMITH'' ')

Gives me this error now.

OLE DB provider "MSDAORA" for linked server "dgtest" returned message "ORA-00904: "SMITH": invalid identifier
".
Msg 7321, Level 16, State 2, Line 1
An error occurred while preparing the query "select * from dgtable.house where upper(LAST_NAME) = "SMITH" " for execution against OLE DB provider "MSDAORA" for linked server "dgtest".
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20283439
not double quotes ("), the single quotes ('')

looks like the same, but is not.
0
 

Author Comment

by:brooksmato
ID: 20283509
Angellll-
You rock! Thanks a bunch.

Brooks
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Screencast - Getting to Know the Pipeline

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question