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 2008 Forums
 Transact-SQL (2008)
 Insert and select

Author  Topic 

sqlbasic_2008
Starting Member

6 Posts

Posted - 2009-05-05 : 13:41:03
Hi,
I'd like to insert a record in a table with a new value in one column only and copy the values in the other columns from another row in the same table. How do i do this?
Please help!
Thank you.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-05-05 : 13:43:06
INSERT INTO Table1 (Column1, Column2, Column3, Column4)
SELECT 'SomeValue', Column2, Column3, Column4
FROM Table1
WHERE ...

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

sqlbasic_2008
Starting Member

6 Posts

Posted - 2009-05-05 : 13:48:18
Thank you!
When i execute it, the following error occurs:
Cannot insert explicit value for identity column in table 'Table1' when IDENTITY_INSERT is set to OFF.
Pelase advice.
Go to Top of Page

sqlbasic_2008
Starting Member

6 Posts

Posted - 2009-05-05 : 14:06:34
Never mind, got it. The ID is automatically generated and so removed this from the query. Thanks a lot tkizer for your help!
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-05-05 : 14:22:14
You're welcome.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -