Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Why this UNION don't work ?¿?

Author  Topic 

Cyanider
Starting Member

7 Posts

Posted - 2004-10-26 : 10:19:36
I want to do this:

SELECT Cod_radicado, Tipo_registro, Ano_radicado, Fecha_creacion, Fecha_gestion,
Elaborador, (u.Nombres + ' ' + u.Apellidos) AS Remitentes, (us.Nombres + ' ' + us.Apellidos) AS Corresponsales,
Referencia, Guia, Enviado, Flag, Anulado
FROM datosdocumento, usuarios u, usuarios us
WHERE Tipo_registro = 'ME' AND u.Codigo_usuario = CONVERT(int, Remitente) AND us.Codigo_usuario = CONVERT(int, Corresponsal)
UNION
SELECT Cod_radicado, Tipo_registro, Ano_radicado, Fecha_creacion, Fecha_gestion,
Elaborador, (u.Nombres + ' ' + u.Apellidos) AS Remitentes, Nombre_corresponsal AS Corresponsales,
Referencia, Guia, Enviado, Flag, Anulado
FROM datosdocumento, usuarios u, corresponsales
WHERE Tipo_registro <> 'ME' AND u.Codigo_usuario = CONVERT(int, Remitente) AND Codigo_corresponsal = CONVERT(int, Corresponsal)


But the column 'Referencia' its a text datatype.

How can i join this 2 queries showing the text column data ?¿?

Plz help

surefooted
Posting Yak Master

188 Posts

Posted - 2004-10-26 : 10:29:17
I think it may be trying to eliminate dupliates with just the union operator kind of like a distinct. Blob fields like Text nText and Image can be too large for SQL to compare for a distinct-like clause. Try using union all. That should return what you need.

SELECT Cod_radicado, Tipo_registro, Ano_radicado, Fecha_creacion, Fecha_gestion,
Elaborador, (u.Nombres + ' ' + u.Apellidos) AS Remitentes, (us.Nombres + ' ' + us.Apellidos) AS Corresponsales,
Referencia, Guia, Enviado, Flag, Anulado
FROM datosdocumento, usuarios u, usuarios us
WHERE Tipo_registro = 'ME' AND u.Codigo_usuario = CONVERT(int, Remitente) AND us.Codigo_usuario = CONVERT(int, Corresponsal)
UNION ALL
SELECT Cod_radicado, Tipo_registro, Ano_radicado, Fecha_creacion, Fecha_gestion,
Elaborador, (u.Nombres + ' ' + u.Apellidos) AS Remitentes, Nombre_corresponsal AS Corresponsales,
Referencia, Guia, Enviado, Flag, Anulado
FROM datosdocumento, usuarios u, corresponsales
WHERE Tipo_registro <> 'ME' AND u.Codigo_usuario = CONVERT(int, Remitente) AND Codigo_corresponsal = CONVERT(int, Corresponsal)


-Jon
Should still be a "Starting Member" .
Go to Top of Page

Cyanider
Starting Member

7 Posts

Posted - 2004-10-26 : 10:46:19
OMG i'm a dvmb4$$, UNION ALL was the key, very thanks to you and your wang.

And if u wonder, yes, i'm 2n00b2bhere :(
Go to Top of Page
   

- Advertisement -