I have two tables:
Table1:
RulesVectorID(nullable, primary),Weight,IsDeleted
Table2:
RulesVectorID(forigen) , Weight,IsDeleted, NumberOfOffers, other fields...
I want to do tow things:
-
assign
Idto all rows in table1where RulesVectorID ==nullI tried this:
UPDATE myTable1 SET RulesVectorID = SELECT MAX(RulesVectorID) + 1 FROM myTable1, WHERE RulesVectorID IS NULL -
To rows added in step (1) I want to copy their
Weight, IsDeletedcolumns and add 1 to theirNumberOfOffersI tried this:
INSERT INTO myTable2 (Weight, IsDeleted, NumberOfOffers, RulesVectorID) VALUES ( SELECT Weight, IsDeleted, 1, RulesVectorID FROM myTable1 WHERE myTable1.RulesVectorID NOT IN (SELECT RulesVectorID FROM myTable2))
Is there any cleaner way to do it?
Second query looks ok once you drop the
values()