What's wrong with this access query? Query Builder doesn't like it?

I am configuring a Table Adapter using following access query. This is an exact copy of the query that is saved on the access database. Now the Query Builder is complaining about

Error in list of function arguments: 'IS' not recognized.
Error in list of function arguments: '=' not recognized.
Unable to parse query text.

and

Undefined function '[Year]' in expression

what am i doing wrong? here's the query
SELECT
CD.CompanyCode,
CF.CompanyKey,
CF.PeriodEndDate,
IIF(CF.AnalystDate IS NULL, DATESERIAL(YEAR(CF.PeriodEndDate),MONTH(CF.PeriodEndDate)+2,DAY(CF.PeriodEndDate)), CF.AnalystDate) AS [Analysis Date],
CF.MonthEndClose * CF.OrdinaryShares AS [Market Cap],
IIF(CF.FiguresType = 'A',1,0) AS [Type of results],
CF.Risk AS [Health Score],
CF.RiskRating AS [Health Rating],
CF.ROA,
CF.ROE,
SI.IndustryCode AS [Industry Group Code],
I.IndustryName AS [Industry Group Desc]

FROM ((CompanyDetails AS CD INNER JOIN CompanyFigures AS CF ON CD.CompanyKey = CF.CompanyKey)
LEFT JOIN tblSubIndustry AS SI ON CF.SubIndustryCode = SI.SubIndustryCode)
LEFT JOIN tblIndustry AS I ON SI.IndustryCode = I.IndustryCode
WHERE CF.PeriodEndDate Between #01-JUL-1996# And #30-JUN-2005#
AND DATEDIFF('m',CF.PeriodEndDate, IIF(CF.AnalystDate IS NULL, DATESERIAL(YEAR(CF.PeriodEndDate),MONTH(CF.PeriodEndDate)+2,DAY(CF.PeriodEndDate)), CF.AnalystDate)) <= 4
ORDER BY CF.CompanyKey, CF.PeriodEndDate

[1500 byte] By [JobLot] at [2007-12-16]
# 1
Hi,
If its in access, my best guess would be to change the CF.AnalystDate IS NULL statement in your IIF() to ISNULL(CF.AnalystDate)...
There are many differences in SQL Statements on Access and SQL Server. One of this is the ISNULL() funciton ISNULL() in sqlserver replaces a certain value when a field is null, while in access it just checks if the field is null and return a boolean...

cheers,
Paul June A. Domag

PaulDomag at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 2
But even if i have selected OLE BD Provider why does query builder looks for SQL Server functions?
JobLot at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 3

Hi,

I have the same question with year, month function. I have found something like {fn MothName(Month(...))} ODBC syntax. Unfortunatelly neither I am able to use it properly nor find any other information.

Did you find any solution yet?

Jirka Nouza

JirkaNouza at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 4

I have found that I can run a query using Access query builder works fine but the same query does not work in the "TableAdapter Query Configuration Wizard". Why is this?

Example:

SELECT * from Rental_Agreement
WHERE DateSerial(year(end_date), month(end_date) , day(end_date) - 5) = Date()

This works in Acess 2003 but not in the "TableAdapter Query Configuration Wizard".

Amy comments from Microsoft ?

ComputerGuy at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 5

Hi,

This might be because access does not fully conform to the ansi-sql standards. Some functions in access would not work on other sql-based DBMS just like in your case, DateSerial. The function is not supported on Sql. So I think this is the reason why it wouldn't also work on TableAdapter Query Configuration Wizard to avoid incompatibilities with other database systems. I guess what you should do is to just use the Date functions available in ans-sql to mimic the behavior of the dateserial function of access.

cheers,

Paul June A. Domag

PaulDomag at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 6

Thanks Paul that makes sense. Can you point me to where I might obtain a list of ans and ansi sql commands?

Regards

ComputerGuy at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 7

Hi,

You can start in the sql server books online on the msdn site.

cheers,

Paul June A. Domag

PaulDomag at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...

.NET Development

Site Classified