I keep trying to run the piece of code below on one of my databases and I am getting and error that says the following:
Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near '8000'.
Any ideas? Its probably something simple that I am overlooking (like a missing tick somewhere).
DECLARE @Database varchar(100)
DECLARE @Command nvarchar(200)
SELECT @Database = 'Bank_PROD'
SELECT @Command = 'SELECT ' +@Database+ ' AS dbname,Left(SUBSTRING(dbo.program, PATINDEX(''%[0-9.-]%'', dbo.program), 8000), PATINDEX(''%[^0-9.-]%'', SUBSTRING(dbo.program, PATINDEX(''%[0-9.-]%'', dbo.program), 8000) + ''X'')-1) AS Schema_Version
FROM ' +@Database + '.dbo.scriptdef
WHERE (dbo.program LIKE ''%sub schema_Version%'')'
EXEC(@Command)