Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Proc to copy records into the same table

Status
Not open for further replies.

marcela24

Programmer
Feb 17, 2003
72
0
0
NL
I have this procedure:

CREATE PROC proc_copia_pontos

AS
BEGIN
SET NOCOUNT ON

DECLARE @count INT, @i INT, @tab_ponto TABLE ( latitude nvarchar(200), longitude nvarchar(200), precisao INT, dtponto DATETIME, idpontoOrigem INT, flagCorrecao INT )

INSERT @tab_ponto
SELECT latitude, longitude, precisao, dtponto,
idpontoOrigem, flagCorrecao
from tpontos
where id_veiculo='EF48D360-2B0D-47BC-B1BA-0BF6D85BCC17'
and dtponto > '2003-06-07 00:00:00' and dtponto
'2003-06-08 23:59:59' and precisao < '290'

SET @count = SELECT COUNT(*) FROM @tab_ponto

SET @i = 0

WHILE ( @i < @count )
BEGIN
INSERT INTO tpontos (

I want to insert into table tpontos the result that i've stored in @tab_ponto. But @tab_ponto doesn't have all the columns that tpontos has. Actually i want to copy the records that had returned into the same table tpontos but now having id_veiculo='7ED8E9C9-1D2B-408C-B7F7-4AC61D5CDC92'

 
<snip>
have all the columns that tpontos has
</snip>

add a column list clause to the insert statement..

e.g. Insert into tpontos(col1,col2....) select * from @tab_ponto




Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top