Thursday, April 30, 2009

UPDATE script with Joins


I know this is basic but we tend to forget the basic stuff, today when a client asked me to update the date from one table into another table with 100's of records i for a moment thought that’s manual data entry and then it struck me a simple update statement will do it. Guess this is bound to happen if you work more at client end and not development.

well here is a sample of what i did and i was amazed that if i had opted for manual data entry it would have taken me hours. and the script took me 5~6 minutes.

here is what i did

update Table1 set Table1.col1= Table2.col2 from Table2 where Table1.Id= Table2.id


of course I could have used Inner join or any other standard join as and when required.