Link to home
Start Free TrialLog in
Avatar of brooksmato
brooksmato

asked on

Proper syntax for TSQL openquery statement

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?
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of brooksmato
brooksmato

ASKER

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".
not double quotes ("), the single quotes ('')

looks like the same, but is not.
Angellll-
You rock! Thanks a bunch.

Brooks