Hi
I'm having trouble with this stored procedure, could you please help.
This is error I'm getting - running all this via Oracle Sql developer on SQL Server 2000 hosted elsewhere.
Error
Error starting at line 1 in command:
execute dbo.OF_ASEQ_EH_BROWNBIN 'dbo.EH_Brownbin_Josh','Match', 1
Error report:
Incorrect syntax near the keyword 'BEGIN'.
Procedure
ALTER PROCEDURE [dbo].[OF_ASEQ_EH_BROWNBIN]
@JvarTable Varchar(250),
@varColumn Varchar(250),
@optInterval int
AS
declare @Sql_string nvarchar(4000)
declare @myERROR int
declare @myRowCount int
declare @topseed int
declare @stg_topseed varchar(100)
-- Temp table for rows with nulls in specific column
declare @RowCnt int
declare @MaxRows int
declare @col_Name nvarchar(250)
declare @col_UPRN nvarchar(250)
declare @col_JoinedOn smalldatetime
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)
SELECT @myERROR = @@ERROR, @myRowCOUNT = @@ROWCOUNT
IF @myERROR != 0 GOTO HANDLE_ERROR
select @RowCnt = 1
declare @Import table
(
rownum int IDENTITY (1, 1) Primary key NOT NULL ,
col_Name nvarchar(250),
col_UPRN nvarchar(250),
col_JoinedOn smalldatetime
)
set @sql_string = 'insert into @Import (col_Name, col_UPRN, col_JoinedOn) select Name, UPRN, JoinedOn from ' + @JvarTable + ' where ' + @varColumn +' is null'
exec @Sql_string
SELECT @myERROR = @@ERROR, @myRowCOUNT = @@ROWCOUNT
IF @myERROR != 0 GOTO HANDLE_ERROR
select @MaxRows=count(*) from @Import
SELECT @myERROR = @@ERROR, @myRowCOUNT = @@ROWCOUNT
IF @myERROR != 0 GOTO HANDLE_ERROR
-- Next new seed
select @topseed = @topseed + @optInterval
<br/>
while @RowCnt <= @MaxRows
begin
select @col_Name = col_Name from @Import where rownum = @RowCnt
select @col_UPRN = col_UPRN from @Import where rownum = @RowCnt
select @col_JoinedOn = col_JoinedOn from @Import where rownum = @RowCnt
set @Sql_string = 'update ' + @JvarTable + ' set ' + @varColumn + ' = cast((' + @topseed + ') as char) where Name = ''' + @col_Name + ''' and UPRN = ''' + @col_UPRN + ''' and JoinedOn = ''' + @col_JoinedOn + ''' '
exec (@Sql_string)
select @topseed = @topseed + @optInterval
Select @RowCnt = @RowCnt + 1
end
SELECT @myERROR = @@ERROR, @myRowCOUNT = @@ROWCOUNT
IF @myERROR != 0 GOTO HANDLE_ERROR
HANDLE_ERROR:
RETURN @myERROR
end