Ayuda con un query
Publicado por ayuda con un query (42 intervenciones) el 16/06/2008 20:07:05
Hola Amigos, tengo dos tablas en sql una se llama detalle y la otra Movimientos, necesito sacar una consulta de movimientos e ir recorriendo los registros de esa consulta para que los parametros creados en este procedimeinto almacenado tomen los valores de cada registro de la consulta, y luego realice todo lo definido en este procedimiento almacenado¡¡¡
Como hago¿¿¿¿¿por favor ayudenme
CREATE PROCEDURE CARGA --Procedimiento almacenado para cargar el inventario
--Declaracion de parametros
@Pcod_orden Char(6),
@Pcod_producto char(4),
@Pcodigo_unidad char(3),
@Pprecio money,
@Pcanti money
AS
If exists(select * from movimientos where cod_orden=@Pcod_orden and codigo_p=@Pcod_producto and cod_unidad=@Pcodigo_unidad and precio_uni=@Pprecio)
begin
update movimientos
set existencia = existencia+@Pcanti where cod_orden=@Pcod_orden and codigo_p=@Pcod_producto and cod_unidad=@Pcodigo_unidad and precio_uni=@Pprecio
end
else if exists(select * from movimientos where cod_orden=@Pcod_orden and codigo_p=@Pcod_producto and( cod_unidad<>@Pcodigo_unidad or precio_uni<>@Pprecio))
begin
Insert into movimientos (cod_orden,codigo_p,cod_unidad,precio_uni,existencia) values ( @Pcod_orden,@Pcod_producto,@Pcodigo_unidad,@Pprecio,@Pcanti)
end
GO
Como hago¿¿¿¿¿por favor ayudenme
CREATE PROCEDURE CARGA --Procedimiento almacenado para cargar el inventario
--Declaracion de parametros
@Pcod_orden Char(6),
@Pcod_producto char(4),
@Pcodigo_unidad char(3),
@Pprecio money,
@Pcanti money
AS
If exists(select * from movimientos where cod_orden=@Pcod_orden and codigo_p=@Pcod_producto and cod_unidad=@Pcodigo_unidad and precio_uni=@Pprecio)
begin
update movimientos
set existencia = existencia+@Pcanti where cod_orden=@Pcod_orden and codigo_p=@Pcod_producto and cod_unidad=@Pcodigo_unidad and precio_uni=@Pprecio
end
else if exists(select * from movimientos where cod_orden=@Pcod_orden and codigo_p=@Pcod_producto and( cod_unidad<>@Pcodigo_unidad or precio_uni<>@Pprecio))
begin
Insert into movimientos (cod_orden,codigo_p,cod_unidad,precio_uni,existencia) values ( @Pcod_orden,@Pcod_producto,@Pcodigo_unidad,@Pprecio,@Pcanti)
end
GO
Valora esta pregunta


0