CREATE PROCEDURE HappyHolidays ( @DecorLevel int, @height int, @width int ) as /* AUTHOR: STEVE KASS, DREW UNIVERSITY */ SET NOCOUNT ON select top 0 1 as r, space(@width+4) 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 r, 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.8 insert into #Holiday(r,s) select r, stuff(space(@width/2), 1+cast(@width/2-(r*1.0/@height)*(@width/2) as int), cast((1.0*r/@height)*(@width/3) as int), replicate('-',cast((r*1.0/@height)*(@width/3)as int))) + stuff(space(@width/2), 1+cast((r*1.0/@height)*(@width/6) as int), cast((1.0*r/@height)*(@width/3) as int), replicate('-',cast((r*1.0/@height)*(@width/3) as int))) from #index where r = ( select min(r) from #index where r >= @height*0.8) declare @a int set @a = charindex('- ',(select s from #Holiday where r >= @height*0.8)) insert into #Holiday select r, space(@a-1)+'|'+space(@width-@a-@a-2)+'|' from #index where r >= @height*0.8+1 select @a = rand(cast(cast(newid() as binary(8)) as int)) while @decorLevel > 0 begin set @a = 1 while @a < 0.8*@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 HappyHolidays 3,20,50 exec HappyHolidays 7,40,80