Oracle ODBC SQL Command not properly ended - Visual Studio

4county used Ask the Experts™
I am trying to retrieve data from an Oracle 10g database into a simple Visual Studio project.  The sql statement (see below) is very simple and works fine when I run it in SQL Server Management Studio; however, when I try to execute the statement in Visual Studio I get the following error:
ERROR [HY000] [Oracle][ODBC][Ora]ORA-00933:  SQL command not properly ended

As I said, this same command executes with no errors in SQL Server Management Studio.

Any ideas???

select Case
      when UserName = '2085' then 'Hazel'
      when UserName = '2088' then 'Tracie'
      as UserName,
mbrsep, name, transdate, cafield, oldval, newval
from openquery(SEDCCA, '

select anntrandetl.mbrsep, name, transdate, cafield, oldval, newval, oper as UserName
from anntrandetl inner join mbrsepmstr on anntrandetl.mbrsep = mbrsepmstr.mbrsep

where transdate >= '090719' and cafield = 'MAILCODE' AND (UserName = '2085' or UserName = '2088')

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012
Distinguished Expert 2018

Never tried to execute a select statement from Visual Studio using ODBC but...

Try removing all blank lines (might be a posting error) and/or try a semi colon at the end.  Some products like the ';', others do not.


I have removed the blank lines and tried the semi colon.  Neither worked.
I have used this same approach before in Visual Studio and have referred back to some of those previous queries but cannot figure out what the problem is.
Most Valuable Expert 2012
Distinguished Expert 2018

This will be my last guess since I don't have the setup to test anything.

Do any of the previous queries use CASE?  I wonder if the ODBC driver recognizes it.


I thought about that too.  I removed the CASE statement and the results were the same.  I made the statement as simple as I could make it and still get the error.  I'm sure it's a simple solution, but for the life of me I can't find it.

Thanks anyway.
OPENQUERY() is a T-SQL function; it's not valid in Oracle. The error message indicates that you are trying to run the entire query against an Oracle database, while it appears that, when running it in Management Studio, it is executed against an MS SQL database that is linked to Oracle.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial