ClubEnsayos.com - Ensayos de Calidad, Tareas y Monografias
Buscar

Relation Data bases


Enviado por   •  8 de Junio de 2017  •  Informes  •  1.502 Palabras (7 Páginas)  •  166 Visitas

Página 1 de 7

***********************************************

PREGUNTA 1

***********************************************

**************** QUERY ************************

select top (1) p.nombre as [Nombre del Producto], sum(o.cantidad) as [Cantidad],

sum(case when o.cantidad>5 then o.cantidad * p.precio_may

else o.cantidad * p.precio_uni end) as [Total]

from Orden o

INNER JOIN Productos p ON o.id_prod = p.id_prod

group by p.nombre

order by Cantidad

select top (1) p.nombre as [Nombre del Producto], sum(o.cantidad) as [Cantidad],

sum(case when o.cantidad>5 then o.cantidad * p.precio_may

else o.cantidad * p.precio_uni end) as [Total]

from Orden o

INNER JOIN Productos p ON o.id_prod = p.id_prod

group by p.nombre

order by Cantidad DESC

************** TABLA ****************************

CREATE TABLE dbo.ExamenDBR

(

Producto nchar(50) NOT NULL,

Cantidad int NOT NULL,

Total float NOT NULL

)

************* CURSOR 1 (MIN) ****************************

DECLARE @Producto nchar(50),

@Cantidad int,

@Total float

DECLARE CursorInfo CURSOR

FOR

select top (1) p.nombre as [Nombre del Producto], sum(o.cantidad) as [Cantidad],

sum(case when o.cantidad>5 then o.cantidad * p.precio_may

else o.cantidad * p.precio_uni end) as [Total]

from Orden o

INNER JOIN Productos p ON o.id_prod = p.id_prod

group by p.nombre

order by Cantidad

OPEN CursorInfo

FETCH NEXT FROM CursorInfo

INTO @Producto,

@Cantidad,

@Total

WHILE (@@FETCH_STATUS <> -1)

BEGIN

INSERT INTO ExamenDBR

(Producto,

Cantidad,

Total )

VALUES (@Producto,

@Cantidad,

@Total)

FETCH NEXT FROM CursorInfo

INTO @Producto,

@Cantidad,

@Total

END

CLOSE CursorInfo

DEALLOCATE CursorInfo

GO

************* CURSOR 1 (MAX) ****************************

DECLARE @Producto nchar(50),

@Cantidad int,

@Total float

DECLARE CursorInfo CURSOR

FOR

select top (1) p.nombre as [Nombre del Producto], sum(o.cantidad) as [Cantidad],

sum(case when o.cantidad>5 then o.cantidad * p.precio_may

else o.cantidad * p.precio_uni end) as [Total]

from Orden o

INNER JOIN Productos p ON o.id_prod = p.id_prod

group by p.nombre

order by Cantidad DESC

OPEN CursorInfo

FETCH NEXT FROM CursorInfo

INTO @Producto,

@Cantidad,

@Total

WHILE (@@FETCH_STATUS <> -1)

BEGIN

INSERT INTO ExamenDBR

(Producto,

Cantidad,

Total )

VALUES (@Producto,

@Cantidad,

@Total)

FETCH NEXT FROM CursorInfo

INTO @Producto,

@Cantidad,

@Total

END

CLOSE

...

Descargar como (para miembros actualizados)  txt (10.5 Kb)   pdf (55.3 Kb)   docx (18.5 Kb)  
Leer 6 páginas más »
Disponible sólo en Clubensayos.com