Solved

Proper syntax for TSQL openquery statement

Posted on 2007-11-14
4
1,175 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 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 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 142

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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now