Skip to content
Advertisements

SQL Server Square

DECLARE @number int
SET @number = 1
WHILE(@number<=10)
BEGIN
	PRINT CAST(@number as varchar(10)) + ' Square: ' + CAST(@number*@number as varchar(10))
	SET @number = @number + 1
END

1 Square: 1
2 Square: 4
3 Square: 9
4 Square: 16
5 Square: 25
6 Square: 36
7 Square: 49
8 Square: 64
9 Square: 81
10 Square: 100


DECLARE @number int
SET @number = 1
WHILE(@number<=10)
BEGIN
	IF(@number = 7) -- not seven
	BEGIN 
		SET @number = @number + 1
		CONTINUE
	END
	PRINT CAST(@number as varchar(10)) + ' Square: ' + CAST(@number*@number as varchar(10))
	SET @number = @number + 1
END

1 Square: 1
2 Square: 4
3 Square: 9
4 Square: 16
5 Square: 25
6 Square: 36
8 Square: 64
9 Square: 81
10 Square: 100


DECLARE @number int
SET @number = 1

ret:
PRINT CAST(@number as varchar(10)) + ' Square: ' + CAST(@number*@number as varchar(10))
SET @number = @number + 1
WHILE(@number<=10)
GOTO ret

1 Square: 1
2 Square: 4
3 Square: 9
4 Square: 16
5 Square: 25
6 Square: 36
7 Square: 49
8 Square: 64
9 Square: 81
10 Square: 100

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: