Sample for 8513177

0

Please login or register to vote for this query.

(click on this box to dismiss)

Enter Query Description

Computational Science

Q&A for scientists using computers to solve scientific problems

-- Sample for 8513177
-- Enter Query Description

DECLARE @TEST table(
    [PK] [int] NULL,
    [ITEMS] [varchar](50) NULL
) 

insert into @test (pk, items) values (1, '1111')
insert into @test (pk, items) values (2, '2222')
insert into @test (pk, items) values (3, '3333')
insert into @test (pk, items) values (4, '4444')
insert into @test (pk, items) values (6, '6666')
DECLARE @RowCount INT
SET @RowCount = (SELECT COUNT(ITEMS) FROM @test) 

Print @ROWCOUNT


-- Declare an iterator
DECLARE @I INT
-- Initialize the iterator
SET @I = 1

--Loop through the rows of a table 
WHILE (@I <= @RowCount)

BEGIN

Declare @Name varchar(100)

;WITH CTE as 
(SELECT row_number() over (order by pk) rn, items
FROM @TEST)
SELECT @Name = Lower(items) FROM CTE where rn = @i





PRINT 'Row No = ' + CONVERT(VARCHAR(2), @I)

Print @Name

-- Increment the iterator
        SET @I = @I  + 1

END

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results