INDEXing a poor-performing query is like putting sugar on cat food. Understanding and using APPLY, (I) and (II) Paul White Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden Exploring Recursive CTEs by Example Dwain Camps Yeah, so now what I haven't tested it with is: Since you can use both OUTPUT and OUTPUT INTO within the same INSERT, UPDATE, DELETE or MERGE, can you also then use this OUTPUT as composable DML to INSERT into another table. Id = 1On the above query i want to update columns of both table........ Id = 1) d SELECT * FROM ABCSELECT * FROM ABC1For fast, accurate and documented assistance in answering your questions, please read this article.2 was lowest, so it became 2; 3 was second-lowest, so it became 4; and 5 was third-lowest, so it became 6. I have two tables, say, Fruits and Vegetables: tables. 4 is third-lowest; it becomes 6, and so on, until we get: 4, 10, 8, 6, 2, 12, 14 In table form, that would be: UPDATE can only update one table at a time renumbering your numbers on a regular basis seems wrong, and having two tables for essentially the same thing also seems wrong both fruits and vegetables are , and so you should have only one table for produce [sigh] but i already know what you're gonna say, that your tables aren't about fruits and vegetables -- well, sorry, but that's how you posted your complex scenario and that's my answer, you need a single produce table Thanks for the quick response!In this example, the current ordernums, when Fruits and Vegetables are combined, are: 3, 6, 5, 4, 1, 8, 9 They all need to be even numbers in sequence. You're right, my tables are not actually fruits and vegetables; they're actually Video and Audio.USE tempdb GODROP TABLE ABCCREATE TABLE ABC (Id INT, Name VARCHAR(10), [Level] VARCHAR(20))INSERT INTO ABC VALUES (1, 'PK','Already in table'), (2, 'SK','Already in table')DROP TABLE ABC1CREATE TABLE ABC1 (Id INT, Name VARCHAR(10), [Level] VARCHAR(20))INSERT INTO ABC1 VALUES (1, 'KKKKK','Already in table'), (2, 'MMMMM','Already in table')SELECT * FROM ABCSELECT * FROM ABC1----------------------------------------------- INSERT ABC1 (Id, Name, [Level]) SELECT ID, Name, 'First insert' FROM ( UPDATE A SET A.
Yeah, it probably tastes better but are you sure you want to eat it? My temporal SQL musings: Calendar Tables, an Easter SQL, Time Slots and Self-maintaining, Contiguous Effective Dates in Temporal Tables For fast, accurate and documented assistance in answering your questions, please read this article. So, one statement gives you: INSERT into 3 tables DELETE from 1 table, INSERT into 2UPDATE into 1, INSERT into 2MERGE into 1, INSERT into 2?There are some questions where the answer is no and that is totally fine.I often get asked that as it is possible to select two or more tables in a single SELECT statement, is it possible to UPDATE more than one table in a single table.There is another way this one feature can be achieved is via transactions.You can wrap your around your more than one UPDATE statement in a single transaction, this way if one or more statement fails, the entire transaction rolls back.