Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to do var substitution?
Message
From
30/01/2001 15:47:05
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
How to do var substitution?
Miscellaneous
Thread ID:
00470308
Message ID:
00470308
Views:
87
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
Next
Reply
Map
View

Click here to load this message in the networking platform