p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   SQL Server 2000 (http://p2p.wrox.com/forumdisplay.php?f=20)
-   -   Access Query (http://p2p.wrox.com/showthread.php?t=37052)

gre_smi January 11th, 2006 04:02 AM

Access Query
 
Hi All
Could someone assist me with this.I have an Access Query that I try to run but it keeps giving me an error.

[u]Error:-</u>Syntax Error(Missing Operator)In Query Expression 'Instrument.InstrumentCode = GroupsRelationships.Instr_Port_Id LEFT JOIN GroupsCategories On GroupsRelationships.CategoryId = GroupsCategories.CategoryId LEFT JOIN Groups On GroupsCategories.GroupId = Groups.GroupId LEFT JOIN InsCategory On (Instrument.'.

Query:-[u]</u>

SELECT Instrument.InstrumentCode, Instrument.InstrumentDescription, IIf( IsNull,'Unassigned',"GrpName") AS GrpName, IIf( IsNull,'Unassigned',"CategoryName") AS CatName,InsCategory.CategoryDescription, InsSubCategory.SubCategoryDescription,InsClass.Cla ssDescription FROM Instrument LEFT JOIN GroupsRelationships ON Instrument.InstrumentCode = GroupsRelationships.Instr_Port_ID
LEFT JOIN GroupsCategories ON GroupsRelationships.CategoryID = GroupsCategories.CategoryID
LEFT JOIN Groups ON GroupsCategories.GroupID = Groups.GroupID
LEFT JOIN InsCategory ON (Instrument.ReportDate = InsCategory.ReportDate
AND Instrument.RevisionDate = InsCategory.RevisionDate
AND Instrument.CategoryCode = InsCategory.CategoryCode
LEFT JOIN InsClass ON (Instrument.ClassCode = InsClass.ClassCode
AND Instrument.ReportDate = InsClass.ReportDate
AND Instrument.RevisionDate = InsClass.RevisionDate
LEFT JOIN InsSubCategory
ON Instrument.SubCategoryCode = InsSubCategory.SubCategoryCode
AND Instrument.ReportDate = InsSubCategory.ReportDate
AND Instrument.RevisionDate = InsSubCategory.RevisionDate
WHERE Instrument.RevisionDate = DateValue('" & RevisionDate & "')
AND Instrument.ReportDate = DateValue('" & ReportDate & "')
AND Groups.GroupName = ('" & Groups(0) & "')
AND Groups.GroupType = ('" & GroupType & "')
ORDER BY Instrument.InstrumentCode, GroupsRelationships.GroupID DESC ,
GroupsRelationships.CategoryID DESC ,
InsCategory.CategoryDescription, InsSubCategory.SubCategoryDescription, InsClass.ClassDescription

mmcdonal January 11th, 2006 08:40 AM

Without getting into the syntax, Access uses ANSI 89, and SQL 2000 uses ANSI 92, so there may be some syntax screwing this up.

In any event, the better thing to do is to create your query on the SQL server and then just call the result set from the SQL view instead of pulling ALLLLLL the data, and then sorting it on the client.

SQL server will further optimize the view once created, and this will further speed the process.

If you need to further refine the results once on the client machine, just pull the initial query results into a temporary table on the client, and then run additional queries against it there.

HTH

mmcdonal

Jeff Mason January 11th, 2006 08:59 AM

Looks like you're missing at least one ")".

Shouldn't
Code:

... LEFT JOIN InsCategory ON (Instrument.ReportDate = InsCategory.ReportDate
AND Instrument.RevisionDate = InsCategory.RevisionDate
AND Instrument.CategoryCode = InsCategory.CategoryCode
LEFT JOIN InsClass ...

be
Code:

...LEFT JOIN InsCategory ON (Instrument.ReportDate = InsCategory.ReportDate
AND Instrument.RevisionDate = InsCategory.RevisionDate
AND Instrument.CategoryCode = InsCategory.CategoryCode)
LEFT JOIN InsClass ...

You should also consider being consistent in using parenthesis - some of your compound JOIN conditions have them, some don't, making it difficult for a human to parse them.

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com


All times are GMT -4. The time now is 08:30 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.