(no title) (original) (raw)
In a stored procedure I want to be able to dynamically select from a database based on what is provided by the user. The parameters for the proc are @source_server and @source_database.
I want to be able to do a
SELECT ... FROM @source_server.@source_database.dbo.table1
I've tried it like that, but it gives me errors. I've tried building it elsewhere like:
DECLARE @complete_source_path varchar(100)
SET @complete_source_path = @source_server + '.' + @source_database + '.dbo.table1'
SELECT @standard_grp_id = @standard_grp_id + convert(varchar, grp_id) + ', '
FROM @complete_source_path
It tells me I must declare the variable @complete_source_path. Anyone got any pointers?