SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How can I get data from specific database
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

grandhi
Starting Member

31 Posts

Posted - 04/29/2013 :  01:59:51  Show Profile  Reply with Quote
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

Malaysia
961 Posts

Posted - 04/29/2013 :  02:24:45  Show Profile  Reply with Quote
select * from base2..EmployeeDetails ?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 04/29/2013 :  02:29:59  Show Profile  Reply with Quote
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

India
4 Posts

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

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 04/30/2013 :  03:54:35  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.31 seconds. Powered By: Snitz Forums 2000