Solved

sql multiple inserts

Posted on 2011-03-23
2
286 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now