Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 printing a pattern

Author  Topic 

lou610
Starting Member

2 Posts

Posted - 2012-08-22 : 08:56:43
i am a student studying SQL database management and i was asked to print a pattern containing length and width can someone help me please it is highly important

the pattern must look like this
@@@@@@@@@@
@@@@@@@@@@
@@@@@@@@@@
@@@@@@@@@@

i know i need to use a while loop but need the help thank you in advance

Lourens

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-08-22 : 09:01:28
Well..... if you are using SQL Server 2008 and later, you can do this

print	replicate('@', 10)
go 4



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

YuvarajKrishna
Starting Member

4 Posts

Posted - 2012-08-22 : 10:26:01
Hi lou610 Try once this

CREATE PROC PrintPattern
(
@length int ,
@width int
)
AS
--Declaring Variables
DECLARE @Var NVARCHAR(MAX) = ''
DECLARE @i INT = 0

WHILE @i < @width
BEGIN
SET @Var = @Var+'@'
SET @i = @i+1
END

SET @i = 0

WHILE @i < @length
BEGIN
PRINT @Var
SET @i = @i+1
END


Yuvaraj
Go to Top of Page

xhostx
Constraint Violating Yak Guru

277 Posts

Posted - 2012-08-22 : 10:29:06
quote:
Originally posted by khtan

Well..... if you are using SQL Server 2008 and later, you can do this

print	replicate('@', 10)
go 4



KH
[spoiler]Time is always against us[/spoiler]




Just want to mention that this statement can also be executed unde SQL Server2005

--------------------------
Joins are what RDBMS's do for a living
Go to Top of Page

lou610
Starting Member

2 Posts

Posted - 2012-08-22 : 12:48:10
Thank you but i was just told that the length and width is stored in my database how do i do it then?

Lourens
Go to Top of Page
   

- Advertisement -