1

I have two tables, one holding Floor data (L0 table) and the other Room data (A0 table) which have many columns, but those of interest look something like:

L0 
--------------------------------
auto_key     BLDGCODE   FLOORCODE
--------     --------   ---------
aaaaaaaa     CA0090        01
bbbbbbbb     CA0090        02
cccccccc     CA0090        03
11111111     GB0100        00
22222222     GB0100        01
zzzzzzzz     GB0200        00


A0 (Rooms)
------------------------------------------------
BLDGCODE      FLOORCODE     ROOMID     FloorID
--------      ---------     ------     -------
CA0090           01         01.123
CA0090           01         01.234
CA0090           01         01.345
CA0090           02         02.123
CA0090           02         02.234
CA0900           03         03.123

I want to take the value of auto_key from the L0 table and update the A0 table with that value where the BLDGCODE and FLOORCODE values match.

So I end up with:

A0
--------------------------------------------
BLDGCODE    FLOORCODE    ROOMID     FloorID
--------    ---------    ------     -------
CA0090         01        01.123     aaaaaaaa
CA0090         01        01.234     aaaaaaaa
CA0090         01        01.345     aaaaaaaa
CA0090         02        02.123     bbbbbbbb
CA0090         02        02.234     bbbbbbbb
CA0900         03        03.123     cccccccc

Can anyone please help?

Thanks

FredTheDog
  • 63
  • 1
  • 8
  • What's wrong with an `UPDATE` statement with a `JOIN`? Why didn't your attempt work? What *was* said attempt? – Thom A Feb 22 '22 at 16:49
  • Does this answer your question? [SQL Server - UPDATE data based on SELECT](https://stackoverflow.com/questions/42249175/sql-server-update-data-based-on-select) – SMor Feb 22 '22 at 16:53
  • It does, thanks guys...I don't do this often – FredTheDog Feb 22 '22 at 17:05

0 Answers0