1

I am attempting to fill a column labeled type_match depending on the content of two columns 2018_status and 2019_status in the status_report table.

All three columns are short text. I keep getting a 'syntax error'.

UPDATE status_report AS per  
SET per.type_match = 
Switch(
   per.2018_status = 'No application found', 'No application for 2018',
   per.2019_status = 'No application found', 'NA',
   per.2018_status = per.2019_status, 'Yes',
   True, 'No'
)

The documentation seems pretty straightforward and believe it's an MS Access issue where they tend to be very picky.

1
  • True is totally valid. Commented Jul 5, 2019 at 14:03

2 Answers 2

1

There is nothing wrong with Switch, you only need to enclose in square brackets the column names that have numbers at the start:

UPDATE status_report AS per  
SET per.type_match = 
Switch(
   per.[2018_status] = 'No application found', 'No application for 2018',
   per.[2019_status] = 'No application found', 'NA',
   per.[2018_status] = per.[2019_status], 'Yes',
   True, 'No'
)
Sign up to request clarification or add additional context in comments.

2 Comments

Wow that totally fixed it, I never thought that'd be an issue since I've never enclosed column names with square brackets
Column or table names starting with numbers, or containing spaces, or reserved words, all must be enclosed in square brackets.
0

You can use 1=1 for the default:

UPDATE status_report AS per  
    SET per.type_match = Switch(per.2018_status = "No application found", "No application for 2018,
                                per.2019_status = "No application found", "NA",
                                per.2018_status = per.2019_status, "Yes",
                                1=1, "No"
                         );

MS Access also traditionally uses double quotes for strings, so I changed them as well.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.