[OT] un script navideño :-)

23/12/2004 - 17:26 por Gustavo Larriera [MVP] | Informe spam
Hecho por el MVP Steve Kass... ejecutar en el Query Analyzer, eligiendo
que los resultados salgan en formato texto :-)


USE tempdb
GO

SET NOCOUNT ON
GO

CREATE PROCEDURE HappyHolidays (
@DecorLevel int,
@height int,
@width int
) as

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 7,40,80
go

CREATE PROCEDURE HappyChanukah (
@DecorLevel int,
@height int,
@width int
) as

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
go

drop procedure HappyChanukah
drop procedure HappyHolidays

Gustavo Larriera, MVP SQL http://sqljunkies.com/weblog/gux

Este mensaje se proporciona "como está" sin garantías de ninguna clase,
y no otorga ningún derecho / This message is provided "AS IS" with no
warranties expressed or implied, and confers no rights.

Preguntas similare

Leer las respuestas

#1 Maxi
23/12/2004 - 17:30 | Informe spam
jeje muy bueno :-D


Salu2
Maxi


"Gustavo Larriera [MVP]" escribió
en el mensaje news:
Hecho por el MVP Steve Kass... ejecutar en el Query Analyzer, eligiendo
que los resultados salgan en formato texto :-)


USE tempdb
GO

SET NOCOUNT ON
GO

CREATE PROCEDURE HappyHolidays (
@DecorLevel int,
@height int,
@width int
) as

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(@@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 7,40,80
go

CREATE PROCEDURE HappyChanukah (
@DecorLevel int,
@height int,
@width int
) as

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
go

drop procedure HappyChanukah
drop procedure HappyHolidays

Gustavo Larriera, MVP SQL http://sqljunkies.com/weblog/gux

Este mensaje se proporciona "como está" sin garantías de ninguna clase, y
no otorga ningún derecho / This message is provided "AS IS" with no
warranties expressed or implied, and confers no rights.




email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una preguntaRespuesta Tengo una respuesta
Search Busqueda sugerida