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
 SQL Server Development (2000)
 Fully Qualified Name

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-08-30 : 10:41:03
Ereach writes "Creating a sp and want to use fully qualified name. Iwanted the user to supply the servename and database name while executing the sp.
Below is part of the code I was attempting to write but not successfully so far. Any help is apprecaited.
Declare
@ServerName varchar(128) ,
@databaseName varchar(128)
(select t2.[description] +' from ' + @ServerName + '.' + @databaseName + '.dbo.' + reference_items where t2.keynote = p.keynote) as "status""

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2006-08-30 : 10:55:00
my first question is, why in the world would you do this anyways? Enterprise Manager and Query Analyzer already do this for you.

For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-08-30 : 11:25:32
Ereach,

U may need to use dynamic SQL
http://www.sommarskog.se/dynamic_sql.html

Unless there is no option, its not advisable to do it this way.

Srinika
Go to Top of Page

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2006-08-30 : 19:47:23
I agree there is really no reason to do this, but here it is

Create Procedure Test
@ServerName Varchar(50),
@@databaseName varchar(50)
AS
declare sQuery Varchar(200)

set sQuery = 'select t2.[description] from ' + @ServerName + '.' + @databaseName + '.dbo.reference_items'

exec(sQuery)

/* I didn't leave in your where clause because the tables that were referenced were not declared*/
Go to Top of Page
   

- Advertisement -