0

I'm trying to run a query that will update a field in one table if a field in another table is equal to test. Here is the code:

UPDATE Table1 AS t1 INNER JOIN Table2 AS t2 
ON t1.Field1 = t2.F_Name
SET t1.Field4 =
    (CASE 
        WHEN t2.PlayField = 'test' THEN 'test' 
        ELSE 'No test' 
    END);

However, I always receive a Syntax Error (missing operator) when I run it. Not sure what I'm doing wrong...

1
  • 2
    CASE ... WHEN is not supported in Access SQL. Commented Jun 10, 2015 at 15:45

3 Answers 3

2

Since you only want to understand the issue..Your SQL :

UPDATE Table1 AS t1 INNER JOIN Table2 AS t2 
ON t1.Field1 = t2.F_Name
SET t1.Field4 =
    (CASE 
        WHEN t2.PlayField = 'test' THEN 'test' 
        ELSE 'No test' 
    END);

MS Access doesn't support the CASE statement. It looks like SQL Server, not MS Access.

You could try:

 SET t1.Field4 =
IIf([t2].[playfield]='test','test','No test');

This basically says: Set t1.Field = If t2.PlayField = 'Test', we will use the word 'test', if it doesn't we will use 'No Test'.

Sign up to request clarification or add additional context in comments.

Comments

2

CASE ... WHEN is not supported in Access SQL. Use IIf instead.

UPDATE Table1 AS t1 INNER JOIN Table2 AS t2 
ON t1.Field1 = t2.F_Name
SET t1.Field4 =
    IIf(t2.PlayField = 'test', 'test', 'No test');

2 Comments

Hey! You changed your answer. I swear that IIf expression was not in there.
I was proving my logic in my own database first haha, I am rusty in Access
0

If the question is related to MS Access database engine...

Have a look here: MS Access 2003: Update Query that updates values in one table with values from another table

Your query should look like:

UPDATE TableName
SET TableName.Field1 = (SELECT AnotherTable.Field2
                        FROM AnotherTable
                       WHERE AnotherTable.Field3 = TableName.Field2)
WHERE (<<condition>>);

CASE WHEN ... END statement is only possible to use within VBA. To achieve such as conditional result within query, use IIF function.

See: IIF function

1 Comment

Yes, but I want to know why my script isn't working just so I understand. I was able to update the tables with a simple where statement, but I just want to understand why it's saying I have a missing operator there

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.