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

Posted on 2004-04-29
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
  • 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.

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.


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 500 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sybase - sp_cacheconfig 1 996
Work with Sybase data using SQL Server 2008 7 422
connect to sybase then query 1 744
SQL Query Syntax 11 166
Adding Computers to AD groups through an SCCM Task Sequence
When you have clients or friends from around the world, it becomes a challenge to arrange a meeting or effectively manage your time. This is where Outlook's capability to show 2 time zones in one calendar comes in handy.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 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