troubleshooting Question

how to use for loop or loop the insert statement in Sql Server 2000

Avatar of muneerz
muneerz asked on
Microsoft SQL Server 2005
6 Comments1 Solution1154 ViewsLast Modified:
Hi Experts,

I have a stroed procedure lr which have an insert statement as below:

 
  ALTER Procedure lr

as
my update statement.....

Declare @pc int
Select @pc = MAX(pc)From test.dbo.localtest
Declare @pn nvarchar(50)

Select @pn= pn from test2.dbo.remotetest a where pn NOT IN (Select pn from test.dbo.localtest)

begin
Insert into test.dbo.localtest(pc, pn) VALUES
(@pc+ 1,@pn)

END
 
 
but the above statement is inserting only one record at a time and next statement only after executing the Stored procedure 2nd time and vice versa

I want to keep the insert statement between loop but not getting logic how to loop insert statement.

Please check my above statement  and provide me insert statement with loop code in which at a time all the records should be inserted
 
ALTER Procedure lr
 
as
my update statement.....
 
Declare @pc int 
Select @pc = MAX(pc)From test.dbo.localtest
Declare @pn nvarchar(50) 
 
Select @pn= pn from test2.dbo.remotetest a where pn NOT IN (Select pn from test.dbo.localtest)
 
begin
Insert into test.dbo.localtest(pc, pn) VALUES
(@pc+ 1,@pn)
 
END
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros