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
 Help with Insert sp

Author  Topic 

Pinto
Aged Yak Warrior

590 Posts

Posted - 2008-04-18 : 08:00:26
I want to copy a record from one table to another using an sp. The idea is like this but I need help with the syntax. The fields are identical in each table

Insert into myTable (Select * from Anothertable where RecId = @MyParam

can anyone help with this please ?

nr
SQLTeam MVY

12543 Posts

Posted - 2008-04-18 : 08:07:15
Insert myTable
Select *
from Anothertable
where RecId = @MyParam


It's better to name the columns though
Insert myTable
(col1, col2, ...)
Select col1, col2, ...
from Anothertable
where RecId = @MyParam


==========================================
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

Pinto
Aged Yak Warrior

590 Posts

Posted - 2008-04-18 : 09:39:41
Thanks for your help. The trouble is that I have about 80 columns which is why I didn't want to name them all :-)
Go to Top of Page
   

- Advertisement -