Q

Syntax differences in MS Access

The query you gave in the answer Consolidate data on multiple rows into one (01 August 2003) is not working in

MS Access 2002. Can you please tell me why?


There are three differences in syntax that need to be made so that you can run the query in MS Access.

First, the CASE constructions must be rewritten with IIF functions:

select Name
     , IIF(Food='Fruit','Fruit','') as Fruit
     , IIF(Food='Banana','Banana','') as Banana
     , IIF(Food='Bread','Bread','') as Bread
     , IIF(Food='Pizza','Pizza','') as Pizza
  from yourtable

Next, MS Access does not support derived tables. Well, it didn't in earlier versions, and I have not tested Access 2002, but in any case, there's a workaround. Just save the above query as query ZZZ (or some other name), and then you can use it in the FROM clause.

Finally, concatenation in Access is different, and uses the ampersand. (Access 97 gives the error message "Invalid use of vertical bars" which always struck me as hilarious. I mean, if it's smart enough to recognize them as vertical bars, why doesn't it just do the concatenation? The double vertical bars or pipes are the standard SQL concatenation operator.)

So the query becomes:

select Name
     , max(Fruit)
       & ' ' & max(Banana)
       & ' ' & max(Bread)
       & ' ' & max(Pizza)  as Food
  from ZZZ
group by Name

This was first published in September 2003

Dig deeper on Oracle database design and architecture

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close