Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General » SQL Server »

[SOLUCIONADO] Consulta sobre Utilizar UNION

Estas en el tema de Consulta sobre Utilizar UNION en el foro de SQL Server en Foros del Web. Hola a todos, bueno tengo la siguiente consulta, estoy tratando de unir varias tablas que poseo dentro de mi SQL, al hacerlo me tira el ...
  #1 (permalink)  
Antiguo 31/01/2013, 08:06
 
Fecha de Ingreso: enero-2013
Mensajes: 41
Antigüedad: 11 años, 3 meses
Puntos: 0
Consulta sobre Utilizar UNION

Hola a todos, bueno tengo la siguiente consulta, estoy tratando de unir varias tablas que poseo dentro de mi SQL, al hacerlo me tira el siguiente error,

Cannot resolve the collation conflict between "Modern_Spanish_CI_AS" and "Traditional_Spanish_CI_AS" in the UNION operation.

lo que encontré al respecto es que es un problema de intercalición en las tablas, la verdad es que no se como solucionarlo...:O... si es que alguien me podría ayudar... se los agradecería mucho
  #2 (permalink)  
Antiguo 31/01/2013, 08:07
 
Fecha de Ingreso: enero-2013
Mensajes: 41
Antigüedad: 11 años, 3 meses
Puntos: 0
Respuesta: Consulta sobre Utilizar UNION

ahhh.. estoy en SQL server 2005...
  #3 (permalink)  
Antiguo 31/01/2013, 08:47
 
Fecha de Ingreso: diciembre-2012
Mensajes: 83
Antigüedad: 11 años, 4 meses
Puntos: 4
Respuesta: Consulta sobre Utilizar UNION

Es solo una idea, pero intenta ponerle el mismo nombre a los campos antes del union con el AS por ejemplo.
y debes ver que cada campo del las tablas que haras el union sea exactamente igual al otro, el mismo tipo y del mismo largo, sino tambien te dara problemas.
Saludos
  #4 (permalink)  
Antiguo 31/01/2013, 09:10
 
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'
  #5 (permalink)  
Antiguo 31/01/2013, 09:14
Avatar de Libras
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: En la hermosa perla de occidente
Mensajes: 7.412
Antigüedad: 17 años, 8 meses
Puntos: 774
Respuesta: Consulta sobre Utilizar UNION

el problema no es en el numero de campos del union, o los nombres de los mismos(cosa que no tiene nada que ver en el union, lo que si importa es que sea el mismo numero de campos y el mismo tipo de datos) sino en el collation que tiene cada tabla(ya que se puede manejar un collation diferente para cada tabla)

checate esta liga:

http://blog.sqlauthority.com/2007/06...-to-operation/

y esta:

http://recuerdaprogramacionrapido.bl...-conflict.html

ahora aqui debes de aplicar el collate en la columna que te esta dando conflictos(pero eso lo debes de resolver tu)

saludos!
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me

Etiquetas: sql, tabla, union
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 18:20.