Necesita ayuda con este procedimiento de SQL Server 2000. El problema se dificulta porque estoy probando el procedimiento a través de Oracle SQL Developer.Error de SQL: sintaxis incorrecta cerca de la palabra clave 'Fin'
Estoy ejecutando el procedimiento para iterar la columna con una nueva secuencia de números en formato Varchar para aquellos que tienen valores nulos.
Pero sigo recibiendo errores, entonces a) Pude haber hecho un acercamiento incorrecto b) la sintaxis es incorrecta debido a la versión utilizada. Principalmente soy usuario de Oracle.
Error Sigo recibiendo: SQL Error: Incorrect syntax near the keyword 'End'.
que no es lo suficientemente útil como para solucionarlo. El End
se refiere al último 'Fin' en el procedimiento.
Cualquier ayuda sería muy apreciada.
Aquí está el Procedimiento.
ALTER PROCEDURE [dbo].[OF_AUTOSEQUENCE] @JvarTable Varchar(250), @varColumn Varchar(250), @optIsString char(1), @optInterval int AS
/*
Procedure OF_AUTOSEQUENCE
Created by Joshua [Surname omitted]
When 20100902
Purpose To fill up column with new sequence numbers
Arguments varTable - Table name
varColumn - Column name
optIsString - Option: is it string or numeric, either use T(rue) or F(alse)
optInterval - Steps in increment in building new sequence (Should be 1 (one))
Example script to begin procedure
EXECUTE [dbo].[OF_AUTOSEQUENCE] 'dbo.EH_BrownBin', 'Match', 'T', 1
Any questions about this, please send email to
[business email omitted]
*/
declare
@topseed int,
@stg_topseed varchar(100),
@Sql_string nvarchar(4000),
@myERROR int,
@myRowCount int
set @Sql_string = 'Declare MyCur CURSOR FOR select ' + @varColumn + ' from ' + @JvarTable + ' where ' + @varColumn + ' is null'
Exec sp_executesql @Sql_string
SET NOCOUNT ON
Begin
if @optIsString = 'T'
Begin
set @Sql_string = 'select top 1 ' + @varColumn + ' from ' + @JvarTable + ' order by convert(int, ' + @varColumn + ') desc'
set @stg_topseed = @Sql_string
set @topseed = convert(int, @stg_topseed)
ENd
else
Begin
set @Sql_string = 'select top 1 ' + @varColumn + ' from ' + @JvarTable + ' order by ' + @varColumn + ' desc'
set @topseed = @Sql_string
ENd
-- SELECT @myERROR = @@ERROR, @myRowCOUNT = @@ROWCOUNT
-- IF @myERROR != 0 GOTO HANDLE_ERROR
open MyCur
fetch next from MyCur
WHILE @@FETCH_STATUS = 0
set @topseed = @topseed + @optInterval
if @optIsString = 'T'
begin
set @Sql_string = 'update ' + @JvarTable + ' set ' + @varColumn + ' = cast((' + @topseed + ') as char) where current of ' + MyCur
exec (@Sql_string)
ENd
else
begin
set @Sql_string = 'update ' + @JvarTable + ' set ' + @varColumn + ' = ' + @topseed + ' where current of ' + MyCur
exec (@Sql_string)
ENd
fetch next from MyCur
ENd
-- SELECT @myERROR = @@ERROR, @myRowCOUNT = @@ROWCOUNT
-- IF @myERROR != 0 GOTO HANDLE_ERROR
--HANDLE_ERROR:
--print @myERROR
CLOSE MyCur
DEALLOCATE MyCur
End
Bueno manchado. Ahora tengo un error diferente.
SQL Error: Invalid column name 'MyCur'.
. Tal vez mi enfoque es incorrecto. – Joshuanecesita 'FETCH NEXT FROM MyCur INTO @ a'. entonces, debes declarar una variable local @a previamente y luego cambiar ... '+ 'donde la corriente de' + MyCur' a ...' + 'donde la corriente de' + @ a' –