I have a stored procedure that generates t-sql for shrinking log files for every user database.
Basically the script generated looks something like this:
DBCC SHRINKFILE (N'DB1_log' , 0, TRUNCATEONLY)
DBCC SHRINKFILE (N'DB2_log' , 0, TRUNCATEONLY)
DBCC SHRINKFILE (N'DB3_Log' , 0, TRUNCATEONLY)
Then I put all that t-sql into a variable and execute it:
That gives me an error that seems to be truncated:
Msg 203, Level 16, State 2, Procedure usp_ProcedureName Line 50 The name '
where line 50 is here:
SELECT @i = MIN(database_id)
WHERE database_id > @i
AND (owner_sid <> 1 AND is_distributor<>1) <-- line 50
if I copy the t-sql generated into another query window, it executes successfully. Also if I write it to a .sql file and execute the file from the same stored procedure it also executes sucessfully. Why doesn't EXEC @SQL work?