Solved

sql multiple inserts

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

626 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