on 09-29-2008 6:18 PM
Hola a todos, tengo un problema con las ordenes de ventas, al hacer una orden de venta esta no verifica si hay existencia o no en el almacen, hice un SP para que me validara si el articulo tenia existencia en el stock . Funciona con una sola linea, si hay dos lineas me da error gracias por la ayuda
-- ADD YOUR CODE HERE
IF @object_type='17' and @transaction_type='A'
begin
DECLARE @item1 as varchar(10)
SET @item1 = (SELECT T0.itemcode from rdr1 T0
WHERE T0.DocEntry=@list_of_cols_val_tab_del)
DECLARE @OnHand as varchar(10)
SEt @OnHand=(Select T1.OnHand from oitm T1 WHERE T1.ItemCOde=@item1)
IF @OnHand = '0.000000'
begin
SET @ERROR = 1
SET @error_message = 'No Hay Cantidad disponible en el Stock'
end
end
Hola Juan
esta instrucción te debería devolver mas de 1 registro, los que tendrías que recorrer en un cursor, para validar linea a linea.
SET @item1 = (SELECT T0.itemcode from rdr1 T0
WHERE T0.DocEntry=@list_of_cols_val_tab_del)
suerte
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
intenta con esto.
despues mira la estructura del cursor.
IF @object_type='17' and @transaction_type='A'
begin
declare @ItemCode as varchar(20)
declare @Mensaje as varchar(200)
DECLARE @OnHand as varchar(10)
set @Mensaje=''
declare C cursor for
SELECT T0.itemcode from rdr1 T0
WHERE T0.DocEntry=@list_of_cols_val_tab_del /* esta SQL te entregara mas de 1 registro*/
open C
fetch next from C
into @ItemCode
while @@fetch_status = 0
begin
SEt @OnHand=(Select T1.OnHand from oitm T1 WHERE T1.ItemCode=@ItemCode)
IF @OnHand = '0.000000'
begin
set @Mensaje=@Mensaje+@ItemCode+'-'
end
-- Avanzamos otro registro
fetch next from C
into @ItemCode
end
--cerramos el cursor
close C
deallocate C
if @Mensaje =''
begin
SET @ERROR = 0
SET @error_message = ''
end
else
begin
SET @ERROR = 1
SET @error_message = 'Sin Stock '+@Mensaje
end
end
suerte
pregunta ¿?
funciono el Cursor¿?
esta es la estructura de un CURSOR:
declare @col1 as int
declare @col2 as smallint
declare C cursor for /*se declara el cursor para la SQL*/
select Col1, Col2 from Tabla /*SQL que se cargara en el CURSOR*/
open C /*se abre el cursor*/
fetch next from C
into @col1, @col2 /*asignacion del resultado de la SQL del Cursor a las variable que declaramos*/
while @@fetch_status = 0
begin
/*escribir codigo aca
por ejemplo para hacer un UPDATE
*/
update tabla
set col3='update'
where col1 = @col1
and col2 =@col2
-- Avanzamos otro registro
fetch next from C
into @col1, @col2
end
--cerramos el cursor
close C
deallocate C
Hola Jorge,
Un cursor para algo tan simple? AAAAAAHHHH. Existen muchisimas razon por las cuales se debe evitar al maximo los cursores. En google te puedes informar mas sobre el tema. Pero lo peor creo es ponerlo en el transaction notification! Bueno sin animos de entrar en discusiones, esto tambien soluciona la pregunta sin usar cursores y consultando al almacen donde se hace el pedido.
IF @object_type='17' and @transaction_type='A'
begin
declare @Mensaje as varchar(200)
set @Mensaje=''
if exists(
select 'A'
from RDR1 R1
inner join OITW IW on IW.ItemCode = R1.ItemCode and IW.WhsCode = R1.WhsCode
where R1.DocEntry = @list_of_cols_val_tab_del and IW.OnHand < 0
)
begin
select @Mensaje=''
select @Mensaje = coalesce(@Mensaje + ' ', '; ') + cast(R1.LineNum + 1 as varchar) + '. ' + R1.ItemCode + ' ' + cast(cast(IW.OnHand as numeric(10,2)) as varchar)
from RDR1 R1
inner join OITW IW on IW.ItemCode = R1.ItemCode and IW.WhsCode = R1.WhsCode
where R1.DocEntry = @list_of_cols_val_tab_del and IW.OnHand < 0
SET @ERROR = 1
select @error_message = 'Artículos sin stocks disponibles: ' + @Mensaje
return
end
end
Saludos,
Ian
Miembro de la liga pro defensa del transaction notification.
User | Count |
---|---|
108 | |
12 | |
11 | |
6 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.