It requires a bit of dynamic sql:
USE master;
DECLARE @dbname SYSNAME = N'AdventureWorks2008R2',
@filename NVARCHAR(500) = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL2008R2DEV\MSSQL\DATA\AdventureWorks2008R2_Data.mdf',
@logfilename NVARCHAR(500) = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL2008R2DEV\MSSQL\DATA\AdventureWorks2008R2_log.LDF',
@sql NVARCHAR(MAX);
SET @sql = N'CREATE DATABASE ' + QUOTENAME(@dbname) + N' ON
( FILENAME = N' + QUOTENAME(@filename, '''') + N'),
( FILENAME = N' + QUOTENAME(@logfilename, '''') + N')
FOR ATTACH;'
PRINT @sql
--uncomment when ready
--EXEC(@sql);
GO
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato