Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Query to update a column with the max(col)+1

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-12-22 : 08:30:08
Pratap Bhat writes "Here is my question
I have a table Mtemp which has columns
Ooh,aah,ouch,id
Let us say this table has 6000 records

I need to insert all the records from Mtemp to an other table mOrg with the same columns
Let us say there are one million records in the Morg table.


The requirement before insertion is
i need to join the Mtemp and Morg with the OOh,aah,Ouch columns then take the max of id column from my Morg table increment it and then insert the incremented id into the Morg table.

As i have given above i can make a join ,write Insert into and select statement then do the above . Instead of this i would want to avoid this join because having a join between 6000 and 1 million records doesnt make my query optimised enough. Instead of this i want to write a more optimised query which might recursilvely update the Morg table or use a computed column or something from your knowledge base that might stump me as you have always been doing"
   

- Advertisement -