Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Store Procedures
Message
 
À
15/11/2006 12:35:49
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2000
Divers
Thread ID:
01169951
Message ID:
01169954
Vues:
7
>Hello
>
>I have a question.
>
>If I have something like this.
>
>CREATE PROCEDURE dbo.prueba151106
>@base varchar(20)
>AS
>select * from [CPSI-SERVER].[@base].[dbo].[certificados]
>GO
>
>SQL say " The name of the objet '@base.dbo.certificados' is no valid. "
>
>How can I do to that the store procedure can recive the name of the database
You can't use a variable as database name and/or server name and/or table name. If you want to pass any of these names as parameters you are forced to use so called dynamic SQL:
CREATE PROCEDURE dbo.prueba151106
@base varchar(20)
AS
BEGIN
   DECLARE @cmd varchar(4000)
   SET @cmd = 'select * from [CPSI-SERVER].['+@base+'].[dbo].[certificados]'
   EXEC (@cmd)
END
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform