I wish to drop a database when it exists, like this:
DECLARE @DBNaam varchar(50), @file1 varchar(200), @file2 varchar(200)
SET @DBNaam = 'DBName2'
IF EXISTS(SELECT DBID FROM sysdatabases
WHERE name = @DBNaam)
DROP DATABASE @DBNaam;
I receive an error, indicating a variable cannot be used in the DROP DATABASE command. Now I can easily make a dynamic sql-statement and execute that, which I would rather not do.
Can any1 explain why this does not work? Do I miss something here?