I have a master table and a copy table. When master table inserted_dt is today date , I want to insert that rows.
But when insert I want to increase copy table id from current max id + 1.
At the moment if there is 3 rows which inserted_dt is today date , below query inserted with same id which only increased once .
example
insert copyTable (id, name, cusId)
select (select max(id) + 1 from copyTable), mst.name, mst.cusId
from copyTable cpy
right join masterTable mst on cpy.cusId = mst.cusId
where mst.inserted_dt = @todayDate
Actual Result
id | name | cusId |
---|---|---|
190(current max id) | ** | ** |
191(inserted id) | ** | ** |
191(inserted id) | ** | ** |
191(inserted id) | ** | ** |
Expected Result
id | name | cusId |
---|---|---|
190(current max id) | ** | ** |
191(inserted id) | ** | ** |
192(inserted id) | ** | ** |
193(inserted id) | ** | ** |
How can I implement to get my expected result . I look for many solution (like row_number()) on SO but no meet with my wanted..