on 09-03-2010 9:36 PM
Expertos, acudo por su ayuda
tengo el siguiente código de un cursor que necesito para validar el campo TaxCode en la tabla QUT1, me valida muy bien la primera fila, pero en la segunda fila me dice que el cuerso no existe. agradezco su ayuda para resolverlo.
saludos
if (@object_type='23')and (@transaction_type = 'A' or @transaction_type = 'U') begin
Declare @TaxCode nvarchar (3)
Declare cTaxCode cursor for
Select T0.TaxCode
from QUT1 T0
where Docentry = @list_of_cols_val_tab_del
open cTaxCode
Inicio:
FETCH NEXT FROM cTaxCode
INTO @TaxCode
WHILE @@FETCH_STATUS = 0
begin
If @TaxCode is null or @TaxCode = '' begin
select @error = 1
Select @error_message = 'Seleccione indicador de Impuestos (IVA ó EXE)'
Close cTaxCode
Deallocate cTaxCode
goto Fin
FETCH NEXT FROM cTaxCode
INTO @TaxCode
goto Inicio
End
End
end
Close cTaxCode
Deallocate cTaxCode
--------------------------------------------------------------------------------------------------------------------------------
Fin:
-- Select the return values
select @error, @error_message
end
Hola, el problema se presenta por que estas Cerrando y Eliminando el Cursor justo despues que realiza el primer ciclo, ya para el segundo no existe.
if (@object_type='23')and (@transaction_type = 'A' or @transaction_type = 'U') begin
Declare @TaxCode nvarchar (3)
Declare @Line int
Set @Line=1
Declare cTaxCode cursor for
Select T0.TaxCode
from QUT1 T0
where Docentry = @list_of_cols_val_tab_del
open cTaxCode
FETCH NEXT FROM cTaxCode
INTO @TaxCode
WHILE @@FETCH_STATUS = 0
begin
If @TaxCode is null or @TaxCode = '' begin
select @error = 1
Select @error_message = 'Seleccione indicador de Impuestos (IVA ó EXE) linea:' +@Line
-- Close cTaxCode--> ACA ESTAS CERRANDO EL CURSOR ERROR
-- Deallocate cTaxCode--> ACA ESTAS ELIMINANDO EL CURSOR ERROR
end --IF
set @line=@line+1
FETCH NEXT FROM cTaxCode
INTO @TaxCode
End --WHILE
Close cTaxCode
Deallocate cTaxCode
por favor testear.
Saludos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hice las pruebas y no fueron satisfactorias, sin embargo, después de unas modificaciones al código me ha funcionado de perlas
aqui comparto el código. saludos a todos
if (@object_type='23')and (@transaction_type = 'A' or @transaction_type = 'U')
begin
Declare @TaxCode nvarchar (3)
Declare cTaxCode cursor for
Select T0.TaxCode
from QUT1 T0
where Docentry = @list_of_cols_val_tab_del
Open cTaxCode
FETCH NEXT FROM cTaxCode INTO @TaxCode
WHILE @@FETCH_STATUS = 0
begin
If @TaxCode is null or @TaxCode = ''
begin
select @error = 1
Select @error_message = 'Seleccione indicador de Impuestos (IVA ó EXE)'
Close cTaxCode
Deallocate cTaxCode
goto Fin
End
FETCH NEXT FROM cTaxCode INTO @TaxCode
End
Close cTaxCode
Deallocate cTaxCode
end
User | Count |
---|---|
98 | |
11 | |
11 | |
6 | |
6 | |
4 | |
4 | |
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.