Ver Mensaje Individual
  #1 (permalink)  
Antiguo 10/11/2004, 18:31
carlostapia
 
Fecha de Ingreso: septiembre-2004
Mensajes: 141
Antigüedad: 20 años, 5 meses
Puntos: 0
obtener el porcentaje del total en SP como??

hola tengo el siguiente Store procedure que hace una linda tabla y al final quiero que aparte del total que muestra me saque el porcentaje

adjunto mi sp al final estoy haciendo los porcentajes si alguien me peude ayudar

gracias


-----------------------------------------
select distinct tipo_email,tema2_email,0 as EnProceso,0 as Atrasado,0 as Cerrado,0 as CerradoAtrasado,count(*) as TOTAL
into ##r1
from profile
group by tipo_email,tema2_email





select
count(*)as total ,p.tipo_email
into ##r2
from profile p
where estado1=1
group by p.tipo_email

update ##r1 set Enproceso=r2.total
from ##r1 r1, ##r2 r2
where r1.tipo_email=r2.tipo_email




drop table ##r2



select
count(*) total ,p.tipo_email
into ##r3
from profile p
where estado1=2
group by p.tipo_email


update ##r1 set Atrasado=r3.total
from ##r1 r1, ##r3 r3
where r1.tipo_email=r3.tipo_email



drop table ##r3




select
count(*) total ,p.tipo_email
into ##r4
from profile p
where estado1=3
group by p.tipo_email


update ##r1 set Cerrado=r4.total
from ##r1 r1, ##r4 r4
where r1.tipo_email=r4.tipo_email

drop table ##r4



select
count(*) total ,p.tipo_email
into ##r5
from profile p
where estado1=4
group by p.tipo_email


update ##r1 set CerradoAtrasado=r5.total
from ##r1 r1, ##r5 r5
where r1.tipo_email=r5.tipo_email

select * from ##r1
drop table ##r5
drop table ##r1

----------------------------------------
declare @TotalX int
select @TotalX = TOtAL from ##r1

select tipo_email , sum(totalx),

((100/@Totalx)*count(*)) as totalP
--convert(float,(@totalX) as Porcentaje
from ##r1
group by tipo_email

----------------------------------------------

GO