Users Pricing

forum

Home Forums SQL: Insert new records from 1 table to another – MindStick

SQL: Insert new records from 1 table to another

Samuel Fernandes 2978 09 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

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

1 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md