Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

sql multiple inserts

Posted on 2011-03-23
2
289 Views
Last Modified: 2012-05-11

the ControlNoBegin is the starting range

and the ControlNoEnd is the ending range

need to insert 'n' records -- according the to above range defined -- and the ControlNo_ID being the unique number each time being recorded within loop

how do you script that with the stored procedure provided ... assuming can just make a single request from .net code behind page to stored procedure to complete updates (multiple inserts)
ALTER PROCEDURE [dbo].[SP_Allocations]

@ControlNoBegin		bigint,
@ControlNoEnd		bigint,
@ActionReason		nvarchar(MAX),
@HTTPBrowserIPAddress	nvarchar(15),
@HTTPBrowserSessionID	nvarchar(50)

AS
BEGIN

INSERT INTO Allocations
			(
				ControlNo_ID,				                   ActionReason,
				HTTPBrowserIPAddress,
				HTTPBrowserSessionID
			)
	VALUES (	
				  @theBeginToEndRangeValue   [ControlNo_ID]				                  @ActionReason,
				@HTTPBrowserIPAddress,
				@HTTPBrowserSessionID
			)
END

Open in new window

0
Comment
Question by:amillyard
2 Comments
 
LVL 32

Accepted Solution

by:
ewangoya earned 500 total points
ID: 35198571
try
ALTER PROCEDURE [dbo].[SP_Allocations]

@ControlNoBegin		bigint,
@ControlNoEnd		bigint,
@ActionReason		nvarchar(MAX),
@HTTPBrowserIPAddress	nvarchar(15),
@HTTPBrowserSessionID	nvarchar(50)


AS
BEGIN

	declare @Index integer

	set @Index = @ControlNoBegin
	while @Index <= @ControlNoEnd
	begin
		INSERT INTO Allocations
					(
						ControlNo_ID,	
						ActionReason,
						HTTPBrowserIPAddress,
						HTTPBrowserSessionID
					)
			VALUES (	
						@Index				                 
						@ActionReason,
						@HTTPBrowserIPAddress,
						@HTTPBrowserSessionID
				)
		set @Index = @Index + 1
	end
END

Open in new window

0
 

Author Closing Comment

by:amillyard
ID: 35198843
superb ! - thank you :-)
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question