I am trying to create a stored procedure that runs a smaller query first to determine the database to run the second query on. Below is a sample query that is similar to what I would be doing. I'm not interested in creating new Stored Procedures as their are hundreds that are like this so I don't want to write new statements like...
EXEC( "Select * from " + @TableName + " where " + CAST(@Param1 as varchar) +
" = " + @Param2
GO
as that would be too many queries to update. Any thoughts?
Thanks
CREATE PROCEDURE dbo.stored_proc edure_name
AS
DECLARE @database varchar(50)
SET @database = (SELECT dbName FROM database.curren tDatabase)
Begin
set nocount on
select * from (@database).dbo .table_name
end
GO
EXEC( "Select * from " + @TableName + " where " + CAST(@Param1 as varchar) +
" = " + @Param2
GO
as that would be too many queries to update. Any thoughts?
Thanks
CREATE PROCEDURE dbo.stored_proc edure_name
AS
DECLARE @database varchar(50)
SET @database = (SELECT dbName FROM database.curren tDatabase)
Begin
set nocount on
select * from (@database).dbo .table_name
end
GO
Comment