Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / DB Engine / SQL Server / July 2008

Tip: Looking for answers? Try searching our database.

loop statement

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mecn - 15 Jul 2008 22:11 GMT
hi,

I have a SP created in a center DB A.
I created a table in A with one field dbname (15 db names)
DBname
db1
db2
db3
db4
.
.
.
.
.

I need to run that SP against all these tables listed in the table by loop
through.

How do I acomplish these by coding?

Thanks,
Eric Isaacs - 16 Jul 2008 00:54 GMT
What does your stored procedure do to these tables?  You might be able
to have it do dynamic SQL against a passed in databasename, similar to
the following:

DECLARE @DBName as VARCHAR(100)

SELECT @DBName = MIN(DBName) FROM A

WHILE @DBName IS NOT NULL
BEGIN --loop

  EXEC('SELECT * FROM ' + @DBName + '.tablename')

 SELECT @DBName = MIN(DBName) FROM A WHERE DBName > @DBName

END --loop

-Eric Isaacs
Mecn - 16 Jul 2008 14:02 GMT
got it. Thanks
> What does your stored procedure do to these tables?  You might be able
> to have it do dynamic SQL against a passed in databasename, similar to
[quoted text clipped - 14 lines]
>
> -Eric Isaacs
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.