How to print the following pattern using SQL server:
*
* *
* * *
* * * *
* * * * *

 Posted by Bandi on 9/30/2013 | Category: Sql Server Interview questions | Views: 4878 | Points: 40
Answer:

For the above pattern We can make use of spt_values table in master database; Otherwise we can generate the simple table too

SELECT REPLICATE( ' * ', number) CustomPattern

FROM (
SELECT distinct number
FROM master.dbo.spt_values
WHERE number between 1 and 5 and type='p'
) T



OUTPUT:
*
* *
* * *
* * * *
* * * * *


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: Tapanpatel09 on: 5/17/2016 | Points: 10
Is there a way to print this pattern in reverse?

Login to post response