CREATE PROCEDURE HappyChanukah ( @DecorLevel int, @height int, @width int ) as /* AUTHOR: STEVE KASS, DREW UNIVERSITY */ SET NOCOUNT ON select top 0 1 as r, space(@width+@width/7) as s into #Holiday from Northwind..Orders set rowcount @height select identity(int,1,1) as r into #index from Northwind..[Order Details] set rowcount 0 insert into #Holiday(r,s) select 1,'' union all select 2, replicate(char(212)+space((@width-9)/8),8)+char(212) insert into #Holiday(r,s) select r, replicate('I'+space((@width-9)/8),8 )+'I' from #index where r between 3 and @height*0.5 insert into #Holiday(r,s) select r, replicate('-',(select max(len(s)) from #Holiday)) from #index where r = ( select min(r) from #index where r >= @height*0.5) insert into #Holiday(r,s) select r + @height*0.5+1, stuff(space(@width/2),cast(@width/2-(1.0*@width*r/@height)/2 as int),1,'/') + stuff(space(@width/2),cast((1.0*@width*r/@height)/2 as int),1,'\') from #index where r < @height*0.5 declare @a int select @a = rand(cast(cast(newid() as binary(8)) as int)) while @decorLevel > 0 begin set @a = @height/2+1 while @a <= @height begin if rand() > 0.4 update #Holiday set s = stuff(s, cast(charindex('/',s)+1+rand()*(charindex('\',s)-charindex('/',s)-2) as int),1,'*') where r = @a set @a = @a + 1 end set @decorLevel = @decorLevel - 1 end select s as [Happy Holidays] from #Holiday order by r go exec HappyChanukah 3,20,50 exec HappyChanukah 7,40,80