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
 Extract data from different database

Author  Topic 

qasimidl
Starting Member

10 Posts

Posted - 2012-05-29 : 02:56:52
my issue is

i have get data from different database on same server
into my datbase ( only selected data not import or export all)
(e.g)
My db name Roaster and table name overtime

other db name HR and table employeesalary

so i have to pick employee salary from HR datbase by employeeno(its also
exist in my Roaster database table )

i want to pass employeeno to Hr datbase from Roaster to extract record
how can i do this ?

thanks

mani_12345
Starting Member

35 Posts

Posted - 2012-05-29 : 05:24:55
send ur query which u have tried
Go to Top of Page

mani_12345
Starting Member

35 Posts

Posted - 2012-05-29 : 05:28:58
give full name for retrvng recrd from more than 2 databases
i.e

dataservername.databasename.schemaname.tablename


Go to Top of Page

vinu.vijayan
Posting Yak Master

227 Posts

Posted - 2012-05-29 : 06:54:16
Something like this:


Select HR.<schema_name>.EmployeeSalary.Salary From HR.<schema_name>.EmployeeSalary
Where HR.<schema_name>.EmployeeSalary.Emp_Id IN (Select Emp_Id From Overtime Where Name = 'qasimidl')


N 28° 33' 11.93148"
E 77° 14' 33.66384"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-29 : 12:24:38
quote:
Originally posted by vinu.vijayan

Something like this:


Select HR.<schema_name>.EmployeeSalary.Salary From HR.<schema_name>.EmployeeSalary
Where HR.<schema_name>.EmployeeSalary.Emp_Id IN (Select Emp_Id From Overtime Where Name = 'qasimidl')


N 28° 33' 11.93148"
E 77° 14' 33.66384"


learn to use short aliases rather than repeating the full three part name everywhere


Select h.Salary
From HR.<schema_name>.EmployeeSalary h
Where h.Emp_Id IN (Select Emp_Id From Overtime Where Name = 'qasimidl')



Actually, In above case you dont even want alias as query has only single involved table

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -