Declare @Path varchar (4000) Declare Empresas Cursor for Select Codigo from Empresas Order By Codigo Declare @Stat varchar (4000) Declare @Codigo varchar (4) Set @Path = 'D:\Dbs\' Open Empresas Fetch Next from Empresas Into @Codigo While @@FETCH_STATUS = 0 Begin Set @Stat = 'sp_Attach_db EuroPoc' + @Codigo + ', ''' + @Path + 'EuroPoc' + @Codigo + '.mdf''' + ',''' + @Path + 'EuroPoc' + @Codigo + '_log.ldf''' + char(13) + char(10) + 'GO' + char(13) + char (10) Print @Stat Fetch Next from Empresas Into @Codigo End Close Empresas Deallocate Empresas