Help with some code
Hi Everyone, I am having some problems with this piece of code. Can anyone help please?
DECLARE @Command varchar(8000)
Declare @ISBNRoot varchar(7), @ISBNRootlength int
DECLARE Curs INSENSITIVE CURSOR FOR
select ISBNRoot, datalength(Ltrim(Rtrim(ISBNRoot))) from ExporttblISBN order by 2
FOR READ ONLY
OPEN Curs
FETCH NEXT FROM curs INTO @ISBNRoot, @ISBNRootlength
WHILE (@@fetch_status <> -1) and @@fetch_status <> -2 BEGIN
select @Command = "Update #tempT1 set ISBN = Left(ISBN, 1) + '-' + "
--select @Command = "Select ISBN, Left(ISBN, 1) + '-' + "
select @Command = @Command + " substring(ISBN, 2, " + convert(varchar(10), @ISBNRootlength - 2) + ") + '-' + "
select @Command = @Command + " substring(ISBN, " + convert(varchar(10), @ISBNRootlength) + ", " + convert(varchar(10), 10 - @ISBNRootlength) + ") + '-' + "
select @Command = @Command + " + Right(ISBN, 1) "
select @Command = @Command + " From #tempT1 "
select @Command = @Command + " where substring(ISBN,1 , " + convert(varchar(10), @ISBNRootlength - 1) + ") = '" + replace( @ISBNRoot , '-', '') + "'"
select @Command
execute (@Command)
FETCH NEXT FROM curs INTO @ISBNRoot, @ISBNRootlength
END
CLOSE Curs
DEALLOCATE Curs
All I get when I run it is:::::
Server: Msg 207, Level 16, State 3, Line 10
Invalid column name 'Update #tempT1 set ISBN = Left(ISBN, 1) + '-' + '.
Server: Msg 207, Level 16, State 1, Line 12
Invalid column name ' substring(ISBN, 2, '.
Server: Msg 207, Level 16, State 1, Line 12
Invalid column name ') + '-' + '.
Server: Msg 207, Level 16, State 1, Line 13
Invalid column name ' substring(ISBN, '.
Server: Msg 207, Level 16, State 1, Line 13
Invalid column name ', '.
Server: Msg 207, Level 16, State 1, Line 13
Invalid column name ') + '-' + '.
Server: Msg 207, Level 16, State 1, Line 14
Invalid column name ' + Right(ISBN, 1) '.
Server: Msg 207, Level 16, State 1, Line 15
Invalid column name ' From #tempT1 '.
Server: Msg 207, Level 16, State 1, Line 16
Invalid column name ' where substring(ISBN,1 , '.
Server: Msg 207, Level 16, State 1, Line 16
Invalid column name ') = ''.
Server: Msg 207, Level 16, State 1, Line 16
Invalid column name '''.
HELP:(
|