//While loop in SQL Server
CREATE PROCEDURE [dbo].[prc_while]
AS
begin
DECLARE @@i NUMERIC;
DECLARE @@Alfa VARCHAR(max);
SET @@Alfa = '';
SET @@i = 65;
WHILE @@i <=90
BEGIN
SET @@Alfa =@@Alfa+ CHAR(@@i)
SET @@i = @@i +1;
PRINT @@Alfa;
END
END
O/P:=
A
AB
ABC
ABCD
ABCDE
ABCDEF
ABCDEFG
ABCDEFGH
ABCDEFGHI
ABCDEFGHIJ
ABCDEFGHIJK
ABCDEFGHIJKL
ABCDEFGHIJKLM
ABCDEFGHIJKLMN
ABCDEFGHIJKLMNO
ABCDEFGHIJKLMNOP
ABCDEFGHIJKLMNOPQ
ABCDEFGHIJKLMNOPQR
ABCDEFGHIJKLMNOPQRS
ABCDEFGHIJKLMNOPQRST
ABCDEFGHIJKLMNOPQRSTU
ABCDEFGHIJKLMNOPQRSTUV
ABCDEFGHIJKLMNOPQRSTUVW
ABCDEFGHIJKLMNOPQRSTUVWX
ABCDEFGHIJKLMNOPQRSTUVWXY
ABCDEFGHIJKLMNOPQRSTUVWXYZ
CREATE PROCEDURE [dbo].[prc_while]
AS
begin
DECLARE @@i NUMERIC;
DECLARE @@Alfa VARCHAR(max);
SET @@Alfa = '';
SET @@i = 65;
WHILE @@i <=90
BEGIN
SET @@Alfa =@@Alfa+ CHAR(@@i)
SET @@i = @@i +1;
PRINT @@Alfa;
END
END
O/P:=
A
AB
ABC
ABCD
ABCDE
ABCDEF
ABCDEFG
ABCDEFGH
ABCDEFGHI
ABCDEFGHIJ
ABCDEFGHIJK
ABCDEFGHIJKL
ABCDEFGHIJKLM
ABCDEFGHIJKLMN
ABCDEFGHIJKLMNO
ABCDEFGHIJKLMNOP
ABCDEFGHIJKLMNOPQ
ABCDEFGHIJKLMNOPQR
ABCDEFGHIJKLMNOPQRS
ABCDEFGHIJKLMNOPQRST
ABCDEFGHIJKLMNOPQRSTU
ABCDEFGHIJKLMNOPQRSTUV
ABCDEFGHIJKLMNOPQRSTUVW
ABCDEFGHIJKLMNOPQRSTUVWX
ABCDEFGHIJKLMNOPQRSTUVWXY
ABCDEFGHIJKLMNOPQRSTUVWXYZ
No comments:
Post a Comment