Run Querys on List of Databases (For Each loop?)
ALTER DATABASE does not take arguments for database name, so you'll have to construct dynamic SQL, e.g. instead of:

ALTER DATABASE @DBName
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE;


You'll need this:

DECLARE @sql nvarchar(max);

  ... inside loop ...

  SET @sql = N'ALTER DATABASE ' + QUOTENAME(@DBName) 
    + N' SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
    '
    + N'ALTER DATABASE ' + QUOTENAME(@DBName) 
    + N' SET OFFLINE WITH ROLLBACK IMMEDIATE;';

  EXEC sys.sp_executesql @sql;


However assuming you have a backup (and if you don't, you should), why bother detaching? Much cleaner to just drop, then you aren't tempted to use an mdf file as a backup, and you don't have to worry about your data folder being permanently full of abandoned data files...