John
John

Reputation: 69

MS Access IF IIF statement TRUE set two fields to values

I am writing SQL query in MS Access. I came across a need for the following IF statement

IF (branch= 'TEST123') THEN (branch = '123' and subbranch='456')
ELSE branch = 'TEST0'

Looking in google, I only see the IIF statementmki

I am not sure if I can write my IF statement in IIF, correct? is there another way to do this?

I don't think I can write

iif( branch= 'TEST123', branch = '123' AND subbranch='456', 'TEST0')

Any help is appreciated.

Upvotes: 0

Views: 1110

Answers (2)

Praveen DA
Praveen DA

Reputation: 354

try the below query

Update test set  test.branch=iif(branch= "TEST123",  "123", branch = "TEST0"), test.subbranch=iif(branch= "TEST123",  "567", branch = "TEST0")

Upvotes: 0

LeeG
LeeG

Reputation: 728

Two ways:

UPDATE MyTable SET Branch = IIF([Branch] = 'TEST123','123',[Branch]), 
                   SubBranch =  IIF([Branch] = 'TEST123','456',[SubBranch ])

Or with just a simple WHERE

UPDATE MyTable SET Branch = '123', SubBranch = '456' WHERE Branch = 'TEST123'

2nd option is better.

Upvotes: 1

Related Questions