forum

Home / DeveloperSection / Forums / SQL: Insert new records from 1 table to another

SQL: Insert new records from 1 table to another

Samuel Fernandes260409-May-2013
Hi Everyone!

I want to update table from another table data using stored procedure in SQL server. For example I have two table tbl_1 and tbl_2. I want to copy new insert data of tbl_1 to tbl_2.

my stored procedure as following

CREATE PROCEDURE [dbo].[CHECK_NEW]

AS
begin transaction

declare @tempId int
declare @tempName varchar

DECLARE c1 CURSOR FOR  
SELECT kId, kName
FROM table1

OPEN c1

FETCH NEXT FROM c1  
INTO @tempId, @tempName

WHILE @@FETCH_STATUS = 0  
BEGIN

if (SELECT sId FROM table2) NOT IN(@tempId)
insert into table(sId, name) values(@tempId, @tempName)
END

please help me!

Thanks in advance

Updated on 09-May-2013

Can you answer this question?


Answer

1 Answers

Liked By