Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Looking for vfp macro substitution equivalent in t-sql
Message
From
13/11/2002 10:52:19
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Looking for vfp macro substitution equivalent in t-sql
Miscellaneous
Thread ID:
00722158
Message ID:
00722158
Views:
114
I am attempting to write a tsql script that will replicate a given operation across all databases on a given sql server (they all have the same tables, sp's etc). So far, I have written the code below. But I don't know of a way to reference a variable name in a tsql statement, or perform the equivalent of macro substition in vfp
For example, for each database in the schema, I want to be able to 'use it', and then do some further operation on it, like create a stored procedure. But the code doesnt work. In the code below the USE statement (which is commented out) doesn't work, nor does the statement:
select * from @ccatlogname.archived

Is this possible in tsql?

TIA




declare @cCatalogName char(100)

declare dblist scroll cursor
for
select catalog_name from master.information_schema.schemata

OPEN dblist



FETCH NEXT FROM dblist
INTO @cCatalogName
print @ccatalogname
WHILE @@FETCH_STATUS = 0
BEGIN
FETCH NEXT FROM dblist
INTO @cCatalogName
SET @ccatalogname=rtrim(@ccatalogname)
print @ccatalogname

/*use @ccatalogname */
select * from @ccatlogname.archived
END

CLOSE dblist
deallocate dblist
Next
Reply
Map
View

Click here to load this message in the networking platform