sql-server: Can I update two table with Single Query?

Posted by RedsDevils on Stack Overflow See other posts from Stack Overflow or by RedsDevils
Published on 2010-04-09T07:05:06Z Indexed on 2010/04/09 7:13 UTC
Read the original article Hit count: 434

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!

© Stack Overflow or respective owner

Related posts about sql-server

Related posts about sql-server-2005