Return to Snippet

Revision: 67561
at October 29, 2014 01:33 by thetwai


Updated Code
DECLARE @links  table 
	(idx smallint Primary Key IDENTITY(1,1)
	, EnrolmentID int) 
INSERT INTO 
	@links
	(EnrolmentID)
SELECT
	e.EnrolmentID
FROM
	ProSolution.dbo.Enrolment e WITH (NOLOCK)
	
-- Start the looping for each row in Temp table	
DECLARE @i int
DECLARE @numrows int      

SET @i = 1

SET @numrows = (SELECT COUNT(*) FROM @links)
--PRINT 'Number of Rows to Loop: ' + CONVERT(varchar(500), @numrows)

IF @numrows > 0
	WHILE (@i <= (SELECT MAX(idx) FROM @links))
	BEGIN			
	
	SELECT @EnrolmentID = EnrolmentID FROM @links WHERE idx = @i;

	-- Do something now
	
	-- INCREASE next one
	SET @i = @i + 1
        END

Revision: 67560
at October 7, 2014 08:25 by thetwai


Initial Code
DECLARE @links  table 
	(idx smallint Primary Key IDENTITY(1,1)
	, EnrolmentID int) 
INSERT INTO 
	@links
	(EnrolmentID)
SELECT
	e.EnrolmentID
FROM
	ProSolution.dbo.Enrolment e WITH (NOLOCK)
	
-- Start the looping for each row in Temp table	
DECLARE @i int
DECLARE @numrows int      

SET @i = 1

SET @numrows = (SELECT COUNT(*) FROM @links)
--PRINT 'Number of Rows to Loop: ' + CONVERT(varchar(500), @numrows)

IF @numrows > 0
	WHILE (@i <= (SELECT MAX(idx) FROM @links))
	BEGIN			
	
	SELECT @EnrolmentID = EnrolmentID FROM @links WHERE idx = @i;

	-- Do something now
	
	-- INCREASE next one
	SET @i = @i + 1

Initial URL


Initial Description
Loop the SQL Result row by row

Initial Title
Loop the SQL Result

Initial Tags


Initial Language
SQL