sql-server: Can I update two table with Single Query?
- by RedsDevils
How can I write single UPDATE query to change value of COL1 to ‘X’ if COL2 < 10 otherwise change it to ‘Y’, where the following two tables are linked by ID
CREATE TABLE TEMP(ID TINYINT, COL1 CHAR(1))
INSERT INTO TEMP(ID,COL1) VALUES (1,'A')
INSERT INTO TEMP(ID,COL1) VALUES (2,'B')
INSERT INTO TEMP(ID,COL1) VALUES (11,'A')
INSERT INTO TEMP(ID,COL1) VALUES (17,'B')
CREATE TABLE TEMP2(ID TINYINT, COL2 TINYINT)
INSERT INTO TEMP2(ID,COL2) VALUES (1,1)
INSERT INTO TEMP2(ID,COL2) VALUES (2,5)
INSERT INTO TEMP2(ID,COL2) VALUES (11,10)
INSERT INTO TEMP2(ID,COL2) VALUES (17,15)
Thanks in advance!