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 last published in September 2003

Dig Deeper on Oracle database design and architecture

PRO+

Content

Find more PRO+ content and other member only offers, here.

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.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close