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
 General SQL Server Forums
 New to SQL Server Programming
 how to create a copy of a specefic record

Author  Topic 

rtutus
Aged Yak Warrior

522 Posts

Posted - 2006-09-01 : 11:07:57
Hi
I have a table with a user column and other columns. User column id the primary key.

I want to create a copy of the record where the user="user1" and insert that copy in the same table in a new created record. But I want the new record to have a value of "user2" in the user column instead of "user1" since it's a primary key

Thanks.

nr
SQLTeam MVY

12543 Posts

Posted - 2006-09-01 : 11:10:55
insert tbl (User, co1, col2, col3, ...)
select 'User2', co1, col2, col3, ...
from tbl
where User = 'User1'


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

rtutus
Aged Yak Warrior

522 Posts

Posted - 2006-09-01 : 11:34:18
Thank you.
I thought there was a way of doing that without going through the headache of specifying the name of all my columns (I have many columns)
Thank you
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2006-09-01 : 11:36:37
select name + ' ,' from syscolumns where id = object_id('mytable') order by colid


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

rtutus
Aged Yak Warrior

522 Posts

Posted - 2006-09-01 : 13:17:55
Can you explain a bit more this last suggestion. And how do i get all the columns exept "user"
Thanks
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-09-02 : 10:06:34
In that query add and name<>'User'

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

rtutus
Aged Yak Warrior

522 Posts

Posted - 2006-09-09 : 07:42:19
Thanks
Go to Top of Page
   

- Advertisement -