Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 how to pass table name with db name on sql server 7.0

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-05-16 : 09:42:04
ashou writes "Hi Gurus,

I like to pass a db name as a parameter in the stored procedure as:

create proc test
@dbname varchar(20) as
declare @sql varchar(255)
set @sql = 'select * from ' + @dbname + '..tablename'
exec(@sql)

the problem is that the server can't recognize the ..
even I do the code like:
set @sql = 'select * from dbname..tablename'
which gives me the same error: Could not locate entry in sysdatabases for database 'select * from dbname'. No entry found with that name. Make sure that the name is entered correctly.

thanks

Ashou"

mr_mist
Grunnio

1870 Posts

Posted - 2003-05-16 : 10:37:29
Read this thread http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=13082



-------
Moo.
Go to Top of Page
   

- Advertisement -