Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Retrieving Data

Author  Topic 

R4J_1
Starting Member

7 Posts

Posted - 2005-10-26 : 06:08:37
Hi,

I was hoping someone would be able to help me, I trying to go through several databases, 111 to be exact, and get the data out of a particular table which is present in all the databases on the same server.

I know how to get the names of the databases from the INFORMATION_SCHEMA, but how can use the name for it to cycle through all the databases and get data out of the one particular table.



sachinsamuel
Constraint Violating Yak Guru

383 Posts

Posted - 2005-10-26 : 06:15:27
Use a cursor or table datatype. Iterate through them and get ur data using Exec, or sp_executeSQL.

regards
Sachin

Go to Top of Page

R4J_1
Starting Member

7 Posts

Posted - 2005-10-26 : 06:37:04
Thanks, How could I iterate through them, sorry am a beginner here.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-10-26 : 06:40:14
Why do you want to do this?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

R4J_1
Starting Member

7 Posts

Posted - 2005-10-26 : 06:45:01
I have several client databases from which i need to retrieve some details stored in a table called users in each db.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-10-26 : 07:01:52
Run this in Query Analyser

select 'Select * from '+catalog_name+'..users' from information_Schema.schemata

Copy the results and paste them in QA
Then run them one by one

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -