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
 How can I get data from specific database

Author  Topic 

grandhi
Starting Member

31 Posts

Posted - 2013-04-29 : 01:59:51
Hi All,

I have 3 databases names are base1,base2and base3.All this databases have only one table name as EmployeeDetails.Name wise same but data wise totally different.

Know,I want to fetch the data from base2.For this Purpose I wrote the following query but it's not working.

select * from EmployeeDetails where DATABASE_Name='base2'

Can anyone help me?

Thank you

waterduck
Aged Yak Warrior

982 Posts

Posted - 2013-04-29 : 02:24:45
select * from base2..EmployeeDetails ?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-04-29 : 02:29:59
I hope all the databases are in same server otherwise you need to connect to correct server before you run the above. Also if you want to do any operations including all of them, you need to create linked servers to link them on a single server

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

Ajit.Rawat3
Starting Member

4 Posts

Posted - 2013-04-29 : 22:56:37
You can try this query:
select * from base2.EmployeeDetails.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-04-30 : 03:54:35
quote:
Originally posted by Ajit.Rawat3

You can try this query:
select * from base2.EmployeeDetails.


wont work as base2 is database

it should be as waterduck suggested

the order is

server.db.schema.table

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -