Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

sql multiple inserts

Posted on 2011-03-23
2
Medium Priority
?
293 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
[X]
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
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article I will describe the Detach & Attach 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.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

719 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