How do I use database and Tables as parameters

Apr 14 2006 5:32 AM

Hi guys!

I want to set database as parameter so that when you select a data you chooos with database to use, I keep getting the same error, my stored procedure is as follows(runned successfully):

>>>>.
Create     procedure proc_TestingDatabases
@databasename varchar (30)
,@tablename varchar (30)

as

execute
('use' + @databasename + 'select * from' + @tablename)
>>>>>>>>>>

but on the application I receive an error saying incorrect systxt near (*).

Then I tested the following one from the book:

>>>>>>>>>>
DECLARE @databasename varchar(30), @tablename varchar(30)
SET @databasename = 'Northwind'
SET @tablename = 'Products'

EXECUTE
('USE' + @databasename + 'SELECT * FROM' + @tablename)
>>>>>>>>>>>>

I receive the same error, but the they have a result as follows:
ProductName
Chai
Chang
Anniseed Syrup


Is the book lying or there is something that I do wrong.

Thanks


Answers (1)