SQL - ayuda en sentecncia de un triger

 
Vista:

ayuda en sentecncia de un triger

Publicado por Mach (1 intervención) el 28/09/2011 21:19:58
create trigger tr_Actualizar_stock_mp_Salida
on Guia_Remision after insert
as
begin
declare @ord_ped varchar(7)
declare @tip_ord int
declare @cant int

select @tip_ord=tip_ord,@ord_ped=ord_ped from inserted
if(@tip_ord=4)
begin
declare @cant_mp int
select @cant_mp = count(d.cod_mp) from detalle_pedido d,MP p where ord_ped='0000019'
and d.cod_mp=p.cod_mp
declare @cont int
set @cont=0
while (@cont<@cant_mp)
set @cont=@cont+1
--el stock actualizado
select max (select top 2 can=p.stock - d.cant from detalle_pedido d,MP p where ord_ped='0000019'
and d.cod_mp=p.cod_mp order by can asc)

update mp set stock=@can where cod_mp=(select top (select @a) Max(cod_mp) from v_cod_mp )
end
end



duda como hacer
select top 2 can=p.stock - d.cant from detalle_pedido d,MP p where ord_ped='0000019'
and d.cod_mp=p.cod_mp order by can asc

esto me vota

20
10

lo cual quiero solo agarrar el primero o solo el ultimo pero estoy usando un while como un contador
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder