views:

99

answers:

2

I've written a query in MS Access. This is a simplified version:

SELECT IIf([category] LIKE "*abc*","DEF",category) AS category
, Month
, Sum(qty) AS [qty] 
FROM [tableX] 
GROUP BY category, Month

The purpose of the query is to sum quantities of a product in different categories for different months. I want to aggregate categories like abc into a single category called ABC. When I view the query in Access the categories are correctly aggregated, but if I select from the query in C# code no aggregation is done.
Any ideas why this is this happening?

+3  A: 

The wildcard for when using the Access database engine's ANSI-92 Query Mode is %, not *.

The Access database engine's OLE DB providers (e.g. via ADO classic, ADO.NET, etc) always use ANSI-92 Query Mode.

The Access UI uses ANSI-89 Query Mode by default but can be put into ANSI-92 Query Mode.

DAO always uses ANSI-89 Query Mode.

Using the (unsupported) ALIKE keyword always uses the '%' wildcard regardless of Query Mode.

Remou
So does ADO directly run the sql behind the query even although it's is saved in the database?
macleojw
As far as I know, it is the connection that runs the SQL, even if it is a stored query, so if the connection is ADO, you need %
Remou
Thanks for the additonal info onedaywhen
macleojw
A: 

if it's working in Access so try to make it as a Query in Access and use it from your APP.

Wael Dalloul
I wasn't wanting to change category to uppercase. I've changed the example to make this clear.
macleojw
sorry I didn't understand the case, try now.
Wael Dalloul