To print pattern we use replicate function in sql. The following code draws diamond with star character. You can change row count changing max value.
Solution 1
1 2 3 4 5 6 7 8 9 10 |
Declare @i int = 0,@max int = 11,@c int = 1 While (@i<@max) Begin Print space(abs((@max-@c)/2))+ Replicate('X',@c) Set @i = @i + 1 if(@i>(@max/2)) Set @c -= 2 else Set @c += 2 End |
Result of Code