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 2005 Forums
 Transact-SQL (2005)
 select record, modify, insert

Author  Topic 

sfjtraps
Yak Posting Veteran

65 Posts

Posted - 2009-07-29 : 14:00:22
How do I select a record from a table, modify a column in that record, and then insert it back into the same table as a new record? Please help. Thanks,

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-07-29 : 14:36:17
INSERT INTO <table>
SELECT field1, field2,... <urcondition for modifying the field> from <table> where <ur condition>
Go to Top of Page

sfjtraps
Yak Posting Veteran

65 Posts

Posted - 2009-07-29 : 15:02:11
This helps, however I'm not sure it's exactly what I'm trying to do. Will this only INSERT selected fields into the table?

More specifically, I'm trying to SELECT an entire record, only modify two columns in that record, and then INSERT it into the same table it came from as a new record.

I'm still trying to understand SQL so please bare with me....

thanks,
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-07-29 : 16:03:43
In the Select statement you will have to select all the columns from the table. You need to write the logic to change the fields that you want to.
Go to Top of Page
   

- Advertisement -