Both exec() and sp_executesql are used for running dynamic SQL commands, just need to prepare the commands as a String object and call the sp_executesql.
Both of exec() and sp_executesql are same, exec() is the new face of sp_executesql has added in SQL Server V9.
declare @com nvarchar(1024);
set @com='create table MyTable'+convert(varchar(3),@i)+'(id int,[name] varchar(64));';
exec sp_executesql @com; --exec(@com);--as same as above, the new face