Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Parameters in store procedure
Message
 
To
19/10/2006 09:31:45
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2000
Miscellaneous
Thread ID:
01163267
Message ID:
01163291
Views:
8
>hi
>
>my question is:
>
>If I have a store procedure where I have someting like "select * from [Server].[database].[dbo].table".
>how can I do to give like parameters, the server and database to store procedure.

You must use dynamic SQL if you pass Server and Database as parameters:
CREATE PROCEDURE MyTest
(
@ServerName   varchar(500),
@DataBaseName varchar(500)
)
AS
BEGIN
    DECLARE @MySql varchar(8000)
    SET @MySql = 'SELECT * FROM '+@ServerName+'.'+@DataBaseName+'.dbo.Table'
    EXEC (@MySql)
END
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform