Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to do var substitution?
Message
De
30/01/2001 15:47:05
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
How to do var substitution?
Divers
Thread ID:
00470308
Message ID:
00470308
Vues:
83
Hello,

I'm trying to figure out how to do an inline variable substitution. I'm attempting to write a SP that cleans up temp tables users tend to leave behind for various reasons. To do this I create a cursor of all databases then I create another cursor with a dynamic drop table statement. In it I reference a declared varible @db_name.

Here is part of my sql
DECLARE tablenames CURSOR FOR
  SELECT 'DROP TABLE ' + user_name(uid) + '.' + o.name
  FROM @db_name..sysobjects o, master.dbo.spt_values v, master.dbo.spt_values x
  WHERE o.name like 'temp%' ... and {add'l clauses}
its the @db_name.sysobjects that does not work. I need it to translate to {databasename}.sysobjects such as upg30.sysobjects. Any suggestions?

TIA,
-Isaac
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform