Ver Mensaje Individual
  #4 (permalink)  
Antiguo 31/01/2013, 09:10
jormufue
 
Fecha de Ingreso: enero-2013
Mensajes: 41
Antigüedad: 11 años, 3 meses
Puntos: 0
Respuesta: Consulta sobre Utilizar UNION

Mira a vista mia encuentro que está exactamente igual todas las tablas que llamo, podrias mirarlo y tu que conoces más al respecto quizas ves algún error que yo no capto.... Muchas gracias por tu tiempo

SELECT
convert(numeric(10,2),isnull((SUM(MONTO)*0.9/1000000),0.00)) as Meta,
convert(numeric(10,2), isnull((SUM(MONTO)/1000000),0.00)) as Monto,
convert(numeric(4),
case
when len(([MES])) > 0 then year([MES])
else year(getdate())
end) as 'Año',
convert(nvarchar(20),
case month([MES])
when 1 then 'Enero'
when 2 then 'Febrero'
when 3 then 'Marzo'
when 4 then 'Abril'
when 5 then 'Mayo'
when 6 then 'Junio'
when 7 then 'Julio'
when 8 then 'Agosto'
when 9 then 'Septiembre'
when 10 then 'Octubre'
when 11 then 'Noviembre'
when 12 then 'Diciembre'
else case month(getdate())
when 1 then 'Enero'
when 2 then 'Febrero'
when 3 then 'Marzo'
when 4 then 'Abril'
when 5 then 'Mayo'
when 6 then 'Junio'
when 7 then 'Julio'
when 8 then 'Agosto'
when 9 then 'Septiembre'
when 10 then 'Octubre'
when 11 then 'Noviembre'
when 12 then 'Diciembre'
else null end
end) as 'Mes',
'Ingresos' as Indicador,
RUT_CLIENTE
FROM TA_INGRESOS
group by RUT_CLIENTE, Mes

UNION

SELECT
Convert (numeric(10,2),isnull(([ISC Service Manager]*0.9),0.00)) as Meta,
convert(numeric(10,2),isnull(([ISC Service Manager]),0.00)) as Monto,
convert(numeric(4),
case
when len(([MES])) > 0 then year([MES])
else year(getdate())
end) as 'Año',
convert(nvarchar(20),
case month([MES])
when 1 then 'Enero'
when 2 then 'Febrero'
when 3 then 'Marzo'
when 4 then 'Abril'
when 5 then 'Mayo'
when 6 then 'Junio'
when 7 then 'Julio'
when 8 then 'Agosto'
when 9 then 'Septiembre'
when 10 then 'Octubre'
when 11 then 'Noviembre'
when 12 then 'Diciembre'
else case month(getdate())
when 1 then 'Enero'
when 2 then 'Febrero'
when 3 then 'Marzo'
when 4 then 'Abril'
when 5 then 'Mayo'
when 6 then 'Junio'
when 7 then 'Julio'
when 8 then 'Agosto'
when 9 then 'Septiembre'
when 10 then 'Octubre'
when 11 then 'Noviembre'
when 12 then 'Diciembre'
else null end
end) as 'Mes',
'ISC' as Indicador,
convert(nvarchar(20),[Rut Cliente Modi]) as 'RUT_CLIENTE'
FROM TA_ISC

UNION
SELECT
convert(numeric(10,2),isnull((SUM(provision)*0.9/1000000),0.00)) as Meta,
convert(numeric(10,2),isnull((SUM(provision)/1000000),0.00)) as Monto,
Convert(numeric(4),aaaa) as Año,
convert(nvarchar(20),
case
when mm='01' then 'Enero'
when mm='02' then 'Febrero'
when mm='03' then 'Marzo'
When mm='04' then 'Abril'
when mm='05' then 'Mayo'
when mm='06' then 'Junio'
When mm='07' then 'Julio'
when mm='08' then 'Agosto'
when mm='09' then 'Septiembre'
when mm='10' then 'Octubre'
when mm='11' then 'Noviembre'
when mm='12' then 'Diciembre'
end)as 'Mes',
'Provision' as 'Indicador',
convert(nvarchar(20),
Case when
len([RUT_CLIENTE]) = 10
then [RUT_CLIENTE]
else case
when len([RUT_CLIENTE]) = 9
then '0' + [RUT_CLIENTE]
else case
when len([RUT_CLIENTE]) = 8
then '00' + [RUT_CLIENTE]
else case
when len([RUT_CLIENTE]) = 7
then '000' + [RUT_CLIENTE]
else case
when len([RUT_CLIENTE]) = 6
then '0000' + [RUT_CLIENTE]
else case
when len([RUT_CLIENTE]) = 5
then '00000' + [RUT_CLIENTE]
else case
when len([RUT_CLIENTE]) = 4
then '000000' + [RUT_CLIENTE]
else case
when len([RUT_CLIENTE]) = 3
then '0000000' + [RUT_CLIENTE]
else case
when len([RUT_CLIENTE]) = 2
then '00000000' + [RUT_CLIENTE]
end end end end end end end end end) as RUT_CLIENTE

FROM TA_MORA
where [des_tipdocum]<>'DEVOLUCION' and
[des_tipdocum]<>'DOC. AUTORIZACION PAGO ADELANTADO' and
[des_tipdocum]<>'LÍQUIDO'and
[des_tipdocum]<>'NOTA DE DEBITO'and
[origen]<>'Refovo' and
[TRAMO_AÑO]<>'2008 y más' and
[TRAMO_AÑO]<>'Vigente' and
[marca_minsal]<>'SI'
group by RUT_CLIENTE,mm,aaaa
having RUT_CLIENTE<>''

UNION

SELECT
Convert (numeric(10,2),isnull(([Afecta_Ingresos]*0.9),0.00)) as Meta,
convert(numeric(10,2),isnull((Afecta_Ingresos),0.0 0)) as Monto,
convert(numeric(4),
case
when len(([Fecha Termino])) > 0 then year([Fecha Termino])
else year(getdate())
end) as 'Año',
MES,
'Resoluciones Comerciales' as Indicador,
convert(nvarchar(20),[Rut Cliente]) as 'RUT_CLIENTE'

FROM TA_NC
where Estado='RRCC Emitida' and year([Fecha Termino])='2012'