UPDATE statement with multiple WHERE conditions

前端 未结 2 1551
一整个雨季
一整个雨季 2021-02-04 04:32

I\'m trying to run an UPDATE query in Access with different WHERE conditions:

UPDATE Table1
SET [Ticker] = \"TXSFI\" WHERE [Acct Numb]          


        
2条回答
  •  攒了一身酷
    2021-02-04 04:53

    It's possible to do this with one single query (without nesting IIFs), no matter how many different WHERE clauses you have.

    This is similar to what I described in my answer here (second part):

    1. Create a temporary table which looks like this:

      Acct Numb      NewTicker
      -------------------------
      *03            TXSFI
      *04            TESEI
      

      You can enter as many new rows as you want, each one with a "filter value" for the account number and a new Ticker value.

    2. Update all values in Table1 with this single query:

      UPDATE Table1
      INNER JOIN tmp ON Table1.[Acct Numb] LIKE tmp.[Acct Numb]
      SET Table1.Ticker = tmp.NewTicker;
      

      Yes, the JOIN part looks strange at first glance, but it's actually possible to join with LIKE.

    3. You can delete the temporary table again when you're finished.

提交回复
热议问题