SQL SERVER Subconsulta
Publicado por Osvaldo (13 intervenciones) el 21/04/2021 22:41:56
Saludos a todos. Deseo recibir nuevamente sus aportes y criticas al código SQL que realice en SQL SERVER en forma de subconsulta. Para lo cual utilice las siguientes tablas.
VENDEDOR
CodVendedor smallint PK
NombreVendedor varchar(50) NOT NULL
PorComision real NOT NULL
FACTURA
NroFactura int PK, identity(1,1)
NroCuenta int FK, NOT NULL
CodVendedor smallint FK,NOT NULL
PorcComision real NOT NULL
CodAgencia smallint FK,NOT NULL
CodDeposito smallint FK,NOT NULL
CodMoneda smallint FK,NOT NULL
FechaCotizacion datetime NOT NULL
MontoCambio money NOT NULL
FechaEmision datetime,
FechaRendicion datetime
Plazo int NOT NULL
PorcDescuento NOT NULL, DEFAULT 0
MontoTotal money
MontoIVA money
MontoNetoIVA money
El enunciado y el código SQL realizado por mí es el siguiente:
/*Listar los datos de los vendedores que no hayan realizado ventas en el año 2012*/
VENDEDOR
CodVendedor smallint PK
NombreVendedor varchar(50) NOT NULL
PorComision real NOT NULL
FACTURA
NroFactura int PK, identity(1,1)
NroCuenta int FK, NOT NULL
CodVendedor smallint FK,NOT NULL
PorcComision real NOT NULL
CodAgencia smallint FK,NOT NULL
CodDeposito smallint FK,NOT NULL
CodMoneda smallint FK,NOT NULL
FechaCotizacion datetime NOT NULL
MontoCambio money NOT NULL
FechaEmision datetime,
FechaRendicion datetime
Plazo int NOT NULL
PorcDescuento NOT NULL, DEFAULT 0
MontoTotal money
MontoIVA money
MontoNetoIVA money
El enunciado y el código SQL realizado por mí es el siguiente:
/*Listar los datos de los vendedores que no hayan realizado ventas en el año 2012*/
1
2
3
select Vendedor.
from vendedor
where NOT EXISTS (Select * from Factura where factura.codvendedor = vendedor.codvendedor and factura.FechaEmision <> year(2012))
Valora esta pregunta


0