I am trying to get this snipp to work.
Targeting SQL 2005 Service Pack 2 (SP2) and newer SQL Server products.
code:
BEGIN
DECLARE @level tinyint;
DECLARE @levelvar tinyint;
IF substring(@@VERSION, 23, 4) != '2000'
BEGIN
select @level = [compatibility_level] from sys.databases where name = DB_name();
SET @levelvar = @level;
EXEC sp_dbcmptlevel ":DATABASE_NAME" @level;
END;
Yes, I donβt need it @levelvar, yes, I could use DB_name()it in sp_dbcmptlevel, yes, I could use it, ALTER TABLEand yes, it IFreturns the wrong value in SQL 2012, but the pain is that it simply cannot be executed in SQL Studio. Error message:
Msg 102, Level 15, State 1, Line 9
Incorrect syntax near '@level'.
How to pass local variable @level/ @levelvarto this stored procedure?
source
share