
05/04/2012, 21:34
|
 | | | Fecha de Ingreso: febrero-2008 Ubicación: Medellín
Mensajes: 336
Antigüedad: 17 años Puntos: 56 | |
Respuesta: Consulta con LEFT OUTER JOIN no devuelve los valores esperados Mira este ejemplo si te sirve.
Código:
create table TABLA_A
(
id int identity not null primary key,
[date] varchar(7),
terry int,
product varchar(4)
)
create table TABLA_B
(
id int identity not null primary key,
[date] varchar(7),
terry int,
product varchar(4),
ganancia int
)
insert into TABLA_A values('01-2011',1,'A')
insert into TABLA_A values('01-2011',1,'B')
insert into TABLA_A values('01-2011',1,'C')
insert into TABLA_B values('01-2011',1,'A',10)
insert into TABLA_B values('01-2011',1,'B',20)
SELECT
A.[date],A.terry,A.product,
ISNULL(B.ganancia,0) AS GANANCIA
FROM
TABLA_A A
LEFT JOIN
TABLA_B B
ON
A.[date] = B.[date] AND
A.terry = B.terry AND
A.product = B.product
me rotorna este resultado
date terry product ganancia
01-2011 1 A 10
01-2011 1 B 20
01-2011 1 C 0 |