declare @path nvarchar(100)='C:\Mikro\v15xx' declare @preDBName nvarchar(100)='MikroDB_V15_' --EXEC master.dbo.sp_detach_db @dbname = N'MikroDB_V15_02._MS' SELECT replace( 'EXEC master.dbo.sp_attach_db ' + '@dbname = '+'N"'+@preDBName+DB_kod+'",'+ '@filename1 = '+'N"'+@path+'\'+DB_kod+'\'+'DATA\'+@preDBName+DB_kod+'._MS'+'",'+ '@filename2 = '+'N"'+@path+'\'+DB_kod+'\'+'DATA\'+@preDBName+DB_kod+'_log'+'.ldf'+'"' ,'"',char(39)), replace( 'EXEC master.dbo.sp_attach_db ' + '@dbname = '+'N"'+@preDBName+DB_kod+'_WORKDATA",'+ '@filename1 = '+'N"'+@path+'\'+DB_kod+'\'+'WORKDATA\'+@preDBName+DB_kod+'_WORKDATA._MS'+'",'+ '@filename2 = '+'N"'+@path+'\'+DB_kod+'\'+'WORKDATA\'+@preDBName+DB_kod+'_WORKDATA_log'+'.ldf'+'"' ,'"',char(39)) FROM VERI_TABANLARI /* EXEC master.dbo.sp_attach_db @dbname = N'MikroDB_V15_09',@filename1= N'C:\Mikro\v15xx\09\DATA\MikroDB_V15_09._MS',@filename2 = N'C:\Mikro\v15xx\09\DATA\MikroDB_V15_09_log.ldf' EXEC master.dbo.sp_attach_db @dbname = N'MikroDB_V15_09',@filename1 = N'C:\Mikro\v15xx\09\DATA\MikroDB_V15_09._MS',@filename2 = N'C:\Mikro\v15xx\09\DATA\MikroDB_V15_09_log._ldf' */