Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Query generated in MS access work on linked sybase tables but not on its own - please translate!

Posted on 2004-04-29
Medium Priority
Last Modified: 2012-06-21
I basically have an access database with linked tables to a Sybase DB.  I need to use this query in an ASP page, but it won't work.  Have also tried in Sybase interactive but still no joy - can anyone help?  I know its a problem with the left and right joins, and I'm guessing just a syntax issue, but not sure what.


SELECT FFUsers.Companies.Name, FFUsers.Assignments.title, FFUsers.Assignments.status, FFUsers.Assignments.assign_no, FFUsers.Assignments.consult_2, FFUsers.Invoices.inv_date, FFUsers.Invoices.inv_type, FFUsers.Consultant_Fees.fee_comment, FFUsers.UsersPreferences.User_Long, FFUsers.Consultant_Fees.rate1

FROM (FFUsers.Consultant_Fees LEFT OUTER JOIN (FFUsers.Invoices INNER JOIN (FFUsers.Assignments INNER JOIN FFUsers.Companies ON FFUsers.Assignments.client_company_guid = FFUsers.Companies.Companies_GUID) ON FFUsers.Invoices.assignments_guid = FFUsers.Assignments.Assignments_guid) ON FFUsers.Consultant_Fees.related_invoice_guid = FFUsers.Invoices.invoice_guid) LEFT OUTER JOIN FFUsers.UsersPreferences ON FFUsers.Consultant_Fees.consultant = FFUsers.UsersPreferences.User_Short

WHERE FFUsers.Assignments.status Like 'Open*' AND Year(FFUsers.Invoices.inv_date)=2004 AND FFUsers.Invoices.inv_type Like 'Stage*'

ORDER BY FFUsers.UsersPreferences.User_Long DESC;
Question by:fraggle5
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3

Author Comment

ID: 10952845
Meant to add - where I've now got LEFT OUTER JOIN now, was just LEFT JOIN in Access - without the OUTER this gave me an error in both ASP/ADO and Interactive SQL.  The query above doesn't give me any errors, just no results - when run in Access I get about 500.

Expert Comment

ID: 10953764
I reformatted this into the a format that makes sense in Sybase.

      FFUsers.Consultant_Fees CF,
      FFUsers.Invoices I,
      FFUsers.Assignments A,
      FFUsers.Companies C,
      FFUsers.UsersPreferences UP
      A.client_company_guid = C.Companies_GUID
      A.client_company_guid = C.Companies_GUID
      I.assignments_guid = A.Assignments_guid
      CF.related_invoice_guid = I.invoice_guid
      CF.consultant = UP.User_Short
      A.status Like 'Open%'
      I.inv_type Like 'Stage%'

Note that in the WHERE clause there are JOINING CLAUSES. These are equivalent to the ON in ANSI-92 Syntax.

A couple of things. I used all INNER JOINS to reformat your SQL. To make an OUTER JOIN use a * in the side of the = that you want all records from. Like this:

A.client_company_guid =* C.Companies_GUID

-- This would yield all rows from C with matching data from A.

A.client_company_guid *= C.Companies_GUID

-- This would yield all rows from A with matching data from C.

Try to get the joins the way you want and run it in Sybase. Then when you get the desired results paste it into Access in SQL View and Access should reformat to what it thinks should work.

If Access doesn't like the reformatted SQL, make it a pass through query and it should go write through the OLE DB Provider and make the call natively on Sybase and return results to Access.


Also, I have never seen * used as a wildcard with a LIKE operator. Usually the format is LIKE '%string%'. Try replacing the * with a %. Access may be a little too forgiving.

Expert Comment

ID: 10953780
Oh yeah, I used Table Aliases. Like FFUsers.UsersPreferences becomes UP. This just makes your code easier to read. I suggest you do that yourself.

In Access, right Click on the table and type the Alias in.

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.


Author Comment

ID: 10960155
Thanks Frostbyte Zero - have made a few modifications and it's (almost) working OK now - using the above with slight modifications it works in Sybase, but not in ASP.  I suspect it's something to do with the *= join syntax - I don't think ASP likes it - I don't get an error, just no results...

PS - ASP doesn't like % as a wildcard, but * works fine hence the change.

PPS - Haven't used aliases as I'm not sure if ASP will like it, and I'd rather minimise the scope for errors.

PPPS - In "FFUsers.Consultant_Fees.related_invoice_guid = FFUsers.Invoices.invoice_guid" I tried to do =* but I get an error - 'Invalid expression in where clause of transact-sql outer join'

SELECT FFUsers.Companies.Name, FFUsers.Assignments.title, FFUsers.Assignments.consult_2, FFUsers.Invoices.inv_date, FFUsers.Invoices.inv_type, FFUsers.Consultant_Fees.fee_comment, FFUsers.UsersPreferences.User_Long, FFUsers.Consultant_Fees.rate1, FFUsers.Consultant_Fees.consultant

FROM FFUsers.Consultant_Fees, FFUsers.Invoices, FFUsers.Assignments, FFUsers.Companies, FFUsers.UsersPreferences

FFUsers.Assignments.client_company_guid = FFUsers.Companies.Companies_GUID
FFUsers.Invoices.assignments_guid = FFUsers.Assignments.Assignments_guid
FFUsers.Consultant_Fees.related_invoice_guid = FFUsers.Invoices.invoice_guid
FFUsers.Consultant_Fees.consultant *= FFUsers.UsersPreferences.User_short
FFUsers.Assignments.status Like 'Open%'
FFUsers.Invoices.inv_type Like 'Stage%'


Expert Comment

ID: 10960989
Are you using ASP or ASP.NET? What version of Sybase?

PS - ASP doesn't like % as a wildcard, but * works fine hence the change.
A: ASP Doesn't care. ACCESS uses a "*". All other SQL RDBMS use a "%"

PPS - Haven't used aliases as I'm not sure if ASP will like it, and I'd rather minimise the scope for errors.
A: ASP Doesn't care. Aliases are a standard practice. ACCESS prefers if you specify it as:

SELECT * FROM yourtable AS youralias

However Sybase will accept:

SELECT * FROM yourtable youralias

PPPS - In "FFUsers.Consultant_Fees.related_invoice_guid = FFUsers.Invoices.invoice_guid" I tried to do =* but I get an error - 'Invalid expression in where clause of transact-sql outer join'
A: ACCESS is still trying to validate the syntax using its own rules. If the SQL works in Sybase, do not change it. Create a Select Query in Access without the Wizard. When the window prompts for you to select a table, close it. From the Main Menu Select Query/SQLSpecific/PassThrough. Then Paste the Query into SQL Pass-Through Query. Then save it.

This will make ACCESS ignore the SQL Syntax and pass it directly into Sybase. The results are returned to ACCESS and are then available to you.

This is a difficult way of doing it. You may be better off avoiding ACCESS altogether and consider connecting directly to SYBASE from ASP. You just have to create a DSN Connection using Sybase ODBC on the IIS Server. Or if you have an OLEDB Compliant Driver, you could set the ConnectionString property directly in your ASP. Having ACCESS in the middle just adds another layer of complexity. Expecially if the data actually resides on SYBASE.

The best way to troubleshoot further errors is to have ASP do a Response.Write SQL (assuming SQL is your SQL String Variable). Copy the output from ASP to your clipboard and paste it into WISQL32 (or whatever you use for testing on Sybase). Then modify your ASP to format the string correctly.


Author Comment

ID: 10961512
I'm using standard ASP on Windows server 2003.  Sybase is ASA 7.0

Re wildcards, I've tried with a % and I get: ADODB.Recordset (0x800A0CC1) Item cannot be found in the collection corresponding to the requested name or ordinal.  Error disappears if I substitute it for a *.  Not a major concern at the moment I think - I've used * on other ASP queries on Sybase and no problems.

Re aliases, thanks - will still leave as is for the time; I don't think it's causing the problem, but I'll use when I get this sorted.

Don't think I made myself clear enough first time around - I used access to do the initial query as that's where I had it originally (and it's easier for me as I can do it using the design wizard without writing the SQL to being with - not my strong point).  Once I had the SQL from access, I then changed it slightly and ran the query directly in Sybase.  The ASP page does not go through access, it goes straight into Sybase.

The query used in the ASP page is exactly as above, except for substituting * for % as wilcards - but in Sybase I get results, and the ASP page shows 0 results - no error message though.

LVL 15

Accepted Solution

namasi_navaretnam earned 2000 total points
ID: 11002168
Few hints:
1) Year not supported in sybase. Use datepart function.
Use this:
datepart(yy, FFusers.Invoices.inv_date)= 2004

2) Ansi syntax is supported in versions above 12.

3) If your sql works from isql. It should also work thru asp code. First verify that you get results running the sql thru isql. Check the error message from asp.

hope that helps.

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Sometimes Administrators rights are not enough. These cases call for the SYSTEM account. The process in this article outlines the steps required to execute commands using the SYSTEM account.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

636 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