Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

sql multiple inserts

Posted on 2011-03-23
2
Medium Priority
?
296 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:
Ephraim Wangoya earned 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

885 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