04/08/2008, 09:07
|
| | | Fecha de Ingreso: agosto-2005 Ubicación: Lima, Peru
Mensajes: 2.951
Antigüedad: 19 años, 5 meses Puntos: 39 | |
Respuesta: tomar un campo del reguistro siguiente Podria ser algo asi:
Código:
create function fn_cantidad
(
@cod_prod int,
@cant_ped int
)
returns int
as
declare @cantidad int
declare @sum_cant int
declare cur_cant cursor for
select cantidad
from tabla
where cod_prod = @cod_prod
for read only
open cur_cant
fetch next from cur_cant into @cantidad
set @sum_cant = cantidad
while @@fetch_status = 0
begin
if @sum_cant >= @cant_ped
begin
/* Todo OK */
return @cant_ped
end
fetch next from cur_cant into @cantidad
set @sum_cant = @sum_cant + @cantidad
end
close cur_cant
deallocate cur_cant
__________________ No repitamos temas, usemos el Motor de busquedas
Plantea bien tu problema: Ayúdanos a ayudarte. |