How can I write a stored procedure which can switch to new databases using something like "use DBASENAME", but without knowing the dbase names before the procedure runs? The example below was my attempt to do this using SP_EXECUTESQL. The reason for this is so that I can call stored procedures within my stored procedure so that they will use the data in the desired dbase.
set nocount on
declare @NSqlStatment as nvarchar(500)
declare @DbaseName as varchar(20)
set @DbaseName = 'poports'
SET @NSqlStatment = 'use ' + @DbaseName
EXEC SP_EXECUTESQL @NSqlStatment