SQL Query From 2 Databases

Feb 4, 2004

Hi Guys

I was wondering if anyone can tell me how to run a query to extract data from 2 different tables in 2 different databases on the same sql server.

Thanks
alot

View 1 Replies


ADVERTISEMENT

Query Around Databases

Apr 26, 2007

I need to query tables on different databases, which all reside on the same database server. How to do this?is it db1.tablex inner join db2.tabley ? 

View 1 Replies View Related

Query Across 2 Databases

Jul 7, 2004

Wonder if you could help.
Am working in an environment where I have an output table in a new SQL db.
The queries to populate and update this table reference tables in another
db on the same server. So effectively, my SQL inserts and update join
tables across databses.
PROBLEM - they seem to take forever to run!
Any ideas / experience with cross db joins queries???????

Regards
Chris

View 1 Replies View Related

How Do I Run An SQL Query Across Two Databases?

Jun 1, 2007

I was hoping someone could assist me. I would like to know how to structure a SQL query in an attempt to compare data across two databases?

For example:

I'd like to know when salary in one database is changed in another and if it has, then list the new salary so I was thinking of something like this:

select DB1.name, DB1.salary
From DB1.EmployeeTable, DB2.EmployeeTable
where DB1.salary <> DB2.salary

Any feedback would be great.

View 2 Replies View Related

Query A List Of Databases

Oct 23, 2006

anyone know how to query a list of databases?

current the sp_helpdb seems cant help me, because it query all the details, i want to do it like select * from database where database id=2

View 5 Replies View Related

Using IN Clause To Query Two Databases

Jan 16, 2005

Hello,

I've put together the following query, but it has been unsuccessful running it so far.


Code:

select * from Contractors.dbo.Contacts
where VendorNo in (select No_ from [BMIS Live Database].dbo.[BMIS Live Database$Vendor]
where [Name] like '%of%')



I receive the following error when I run it in Query Analyzer:


Code:

Server: Msg 446, Level 16, State 9, Line 1
Cannot resolve collation conflict for equal to operation.



I'm trying to grab values from the column, "No_" in the Bmis.. database then only select data from the Contractors database if the VendorNo column holds one of the values grabbed from the Bmis.. database. I think my syntax is just completely wrong but hopefully someone might pick up on my mistakes. Any help would be greatly appreciated, thanks!

Alex

View 2 Replies View Related

Query Attraction For Several Databases

Apr 8, 2008

Hi Experts,



We are having atleast 7 - 8 servers in SQL Server 2000 and 2005 and each constituting around 2- to 30 databases and each database consists with a column related to date format.

We have problem in checking the LEAP YEAR significance in each and every database of every table to verify as there is no problem with the FEBRUARY 29th, to comply with.

I need to check the query which will do for all the databases and their in-built tables.

Can anyone one help me in this regard to check the above criteria.

Thanks in advance.

View 18 Replies View Related

Running Query On All Databases Within An SQL

Oct 3, 2007

Hi,

I'm running SQL 2000 SP4.

On this server I have a few databases. I need to run the below query against each database. Since the server has approx 50 databases this will take time.

Is there any way for me to modify this so as it will automatically
run against each database one at a time and then create a single output file with all the results.

I do not want it to run against all of the databases at the same time as it will kill my server so it must run and gather results on each database at a time.


QUERY to be run

SELECT RelativeFileName

FROM Collection, Saveset

WHERE Collection.CollectionIdentity = Saveset.CollectionIdentity

View 11 Replies View Related

Running A Query On Two Databases

Mar 31, 2008

Hello all,
Can anyone please tell me what query to use for joining two tables in two databases together?

Basically, we have two databases called 'system' and 'site' respectively. The 'system' database has a table called 'users' and each user has a unique id which is also linked to the tables in the 'site' database.

The only problem i have got is, I want to be able to get the actual user names not the unique id and the only way to get this from my SQL statement is to be able to link the uniqueid for each user in the 'site' database to their corresponding uniqueid in the 'system' database.

Please, how can I do this?

View 14 Replies View Related

Run Sql Query On Multiple Databases

Feb 5, 2007

I need to run a same query on 15 different databases and union the results.

Does any of the experts know how to do this with good performance?

Any help is appreciated.

Phil....the only reason i posted in T-Sql is because i will be using this query in reporting services :)

Thanks

View 9 Replies View Related

2 Databases On 2 Servers, 1 Query?

Jan 25, 2008

Hello,

We have adedicated MS-SQL Server for our CRM database and we have another MS-SQL database server for in house applications, written in c#.Net 2.0. To avoid duplicating information already in our CRM database, it would be nice if we could build a query that combined columns from both data sources.Example





Code Snippet

CRM database on Server1
Table Accounts


Columns
AccountID UniqueIdentifier Primary Key

Name NvarChar(50)



Application Database on Server2
Table Transaction


Columns

TransactionID UniqueIdentifier Primary Key

AccountID UniqueIdentifier
Amount Money




Would it be possible to create a T-SQL statement that will select




Code Snippet

Select
Server1.CRM.Accounts.Name,
Server2.Application.Transaction.TransactionID,
Server2.Application.Transaction.AccountID,
Server2.Application.Transaction.Amount



From Server1.CRM.Accounts INNER JOIN Server2.Application.Transaction




ON (Server1.CRM.Accounts.AccountID = Server2.CRM.Transaction.AccountID)


I appreciate there will need to be 2 connections and therefore some credential information would need to be passed too.


Is anything like this possible? I do not wish to copy the Name field from Server1.CRM.Accounts to Server2..Application.Transaction as this is duplication and any change to the value of Server1.CRM.Accounts.Name would not be reflected in the results.


Many thanks for any information provided.

View 3 Replies View Related

Return All Databases Names Using Query?

Jun 17, 2006

Hi, I am trying to get all the databases from MS SQL into a dropdownlist. However, I am not sure how to do that in query ... is there a way to retrieve all databases name using  a query in MS SQL? Thanks.

View 1 Replies View Related

Multiple Databases Access In Query ... HELP ?

Jul 30, 1998

I try to fill a recordset with a query in an asp page to an SQL Server through ODBC connection :
The ODBC connection (eg : DB1Cnnection) is done to one Database (eg : DB1).
and I need to link to another Database (eg : DB2)

it `s like :
set rs=DB1Connection.Execute("Select DB1.xxx FROM TABLE1, TABLE2 WHERE ...")

Please, How do I `tell` to ODBC that TABLE2 is in DB2 ???
HELP !

View 2 Replies View Related

Connecting To 2 Databases Inside One Query

Sep 16, 2004

hi there,
I saw a similar thread before but i've tried it and no luck. I want run a query off a database (stawebdata.branchinfo) then a join into bluepages.phonelist

i've tired

JOIN bluepages.phonelist p

Incorrect syntax near the keyword 'JOIN'.

any ideas... is this possible?

complete code below:

select DISTINCT b.name, b.tel1, b.id, b.telprivate,b.sc, b.manager,b.branchEmail
from branchInfo b
inner
JOIN bluepages.phonelist p on b.name = p.subdepartment
where b.name like 'Sarah' or b.id LIKE '%@keyword%' OR b.county LIKE '%@keyword%' OR b.Area LIKE '%@keyword%' OR b.Manager LIKE '%@keyword%' OR b.AssistantManager LIKE '%@keyword%' OR b.Postcode LIKE '%@keyword%' OR b.PseudoCity LIKE '%@keyword%' OR b.TicketingTA LIKE '%@keyword%' OR b.SLC LIKE '%@keyword%' OR b.ItineraryTA LIKE '%@keyword%' OR b.TIDS LIKE '%@keyword%' OR b.ABTA LIKE '%@keyword%' and
p.department = 'UK Branch' and
b.isbranch <> 'False' or
(p.lastName = '@keyword' or p.firstname = '@keyword')
order by b.name asc
GO

View 2 Replies View Related

Query And Join Between 2 Databases On Same Server?

Nov 9, 2011

I am trying to query 2 SQL databases on the same server and inner joining together.

Databases: Goldmine_MIOA
Goldmine_GMBase

From the "Goldmine_MIOA" database I need to query contact1.* and from the "Goldmine_GMBase" database i need to query cal.

I would then like to inner join both these together.

View 12 Replies View Related

Query Tables In 2 Databases Using JDBC.

May 13, 2004

I need to Query tables in 2 databases after getting a connection. I cannot make this piece of code to work. In db2, oracle this type of code works.


Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String sys = “jdbc:microsoft:sqlserver://192.168.0.152";
conn = DriverManager.getConnection(sys, "name", "pswd");
Statement stmt = conn.createStatement();

ResultSet rs = stmt.executeQuery("SELECT * FROM pubs.jobs");

rs = stmt.executeQuery("SELECT * FROM mydb.myfile");


If I run this I get invalid object “pubs.jobs” error.

Any ideas?
Thanks.

View 4 Replies View Related

Query On SQL Server And MySQL Databases

Aug 21, 2007

I humbly ask for anyone's help...

I have two different databases - one in MySQL (eV12) and the other in SQL Server (Brutus). I am using DBVisualizer to perform queries. In the eV12 db, I have 3 tables to search on. In Brutus db, I have 2 tables to search on.

the problem is, I was asked to compare data from one table in eV12 to Brutus database. Is there a way to search using and SQL statement techniques?

I appreciate your expert opinions.

Regards,
Dor Marchan
student - OCC, Michigan

View 1 Replies View Related

No Available Databases In A New Query In SSMS 2005

Mar 7, 2007

When I create a new query window in SSMS 2005 (SP2) , I do not have any available database in de SQL Editor pane. Though in the Object Explorer window below, I can access all objects of all databases. The only way to query a table is by using the 'Open Table' feature in the Object Explorer window, then right-click on Pane-->SQL .

I also can open a stored procedure, but not modify it as the SQL Editor pane is disabled.

The SQL-Editor pane is available for all the other servertypes (Analysis, Reporting, Integration).

All services all started.

I re-installed completely SQL2005 and SP2 : nothing changed.

What am I missing ???



Versions = Microsoft SQL Server Management Studio 9.00.3042.00

SQL Developer Edition 2005 (Service Pack 2)

Windows XP Pro 5.1 (build 2600 Service Pack 2)



Any help is welcome !!!

View 6 Replies View Related

How Do I Write An Update Query Across 2 Databases.

Jan 4, 2008

I would like to write a query that will join two tables in separate databases (same server). Then update a field in one table using data and criteria from the other.

Its easy to do this in Microsoft Access by linking the tables using ODBC, but I found its not so simple to do directly in SQL Server

Thanks.





View 2 Replies View Related

How To Reference Different Databases On Different Servers In One Query

Apr 28, 2006

 

View 10 Replies View Related

Select Query Form Multiple Databases

Dec 14, 2007

How do I write an sql statement to link tables in two databases and query them? For example: SELECT db1.table1.field1, db2.table1.field1 FROM Table1 INNER JOIN db1.table1.field1 ON db2.table1.field1 = db1.table1.field1
 
Thanks

View 6 Replies View Related

Maximum Number Of Databases Used For Each Query In 2005?

Mar 22, 2006

In MS Sql Server 2000, if you run a stored procedure that query's morethan 8 databases, you get this error gets raised:Maximum number of databases used for each query has been exceeded. Themaximum allowed is 8.In 2005, does this maximum number still exist? if so, is it still 8, orhas the number been increased?Thanks,Mike

View 2 Replies View Related

Query : Running A Job/step In A Loop For ALL Databases

Jul 20, 2005

Hi,I've written a job to export user and database permissions for alld/b's on a server. As you can see below, the T-SQL commands are thesame for each d/b. Can anyone assist with regard to re-writing this sothat any new d/b's added do not require ammending the job (loop)?Thx,GC.use mastergoSELECT db_name()EXEC sp_helpuserEXEC sp_helprotect NULL, NULL, NULL, 'o s'use msdbgoSELECT db_name()EXEC sp_helpuserEXEC sp_helprotect NULL, NULL, NULL, 'o s'use test1goSELECT db_name()EXEC sp_helpuserEXEC sp_helprotect NULL, NULL, NULL, 'o s'use test2goSELECT db_name()EXEC sp_helpuserEXEC sp_helprotect NULL, NULL, NULL, 'o s'

View 1 Replies View Related

Creating A Query That Access Multiply Databases

Dec 10, 2007


Dear Readers,
Is it possible to create a query that access multiple sql express databases? Or is it possible to link a table in one database from another?

View 1 Replies View Related

Fully Qualified Query Accross Databases

Sep 21, 2007

Are there any perfmonace or query optimization limitations or issues that arise when issueing a fully qualified query across multiple databases on the same Instance of SQL Server. In other words are all features of query optimization fully supported in queries that span databases on the same Instance.

View 3 Replies View Related

How To Access 2 Databases On Separate Servers From Within The Same Query

Apr 10, 2008

Hi,

Im trying to access data from a database on another server in a SQL 2005 query.


use Bury2k29.ServiceDeskForms
select .......


but I get the message


could not locate entry in sysdatabases for database 'Burky2k29'. No entry found with that name. Make sure that the name is entered correctly.


Bury2k29 is the name of the server, and ServiceDeskForms is the database I want to access.

When I open a blank query and enter only the code to access that database it runs fine.

Any ideas?

View 4 Replies View Related

Query To Find Databases In Full Mode

May 4, 2007

I have a stored proc that runs through my databases doing transaction logs. Currently it uses database names but this keeps being changed as a database will be added without me knowing. Next thing the transaction log job is goosed.



I really need something along the lines of select db from sys???? where mode = 'Full'



Any help appreciated.



MPM

View 1 Replies View Related

Query To Obtain Users And Privileges From Databases

Apr 24, 2007

Hi to all, is my first post, i need a query or script to obtain all users and privileges from all my databases, someone to help me. I'm learning Administration SQL server 2005.



I know that sys.database_principals and sys.server_principals have information about that, but i need users - privileges of every database.



thank you

View 4 Replies View Related

Entreprise Library - Same Query In All Databases (SQL+Oracle), Is This Possible? URGENT

Sep 12, 2007

It is posible with Entreprise Library to use the SAME QUERY, by example,
"Select isnull(Val,33) from calculs where Col1 is not null" (specific for Sql Server)
to select data from Oracle too ? or the only way is to use specific stored procedures (queries)
wtitten in 2 ways : for Oracle and for Sql Server?
 
Thanks

View 1 Replies View Related

Update Query Joining Tables From Separate Databases

Apr 17, 2008



In database DB1, I have table DB1.dbo.Suppliers1. This table has an ID column of type INT named SUPPL1_ID

In database DB2, I have table DB2.dbo.Suppliers2. This table has an ID column of type INT named SUPPL2_ID
I would like to update DB2.dbo.Suppliers2 based on values from DB1.dbo.Suppliers1 joining on SUPPL1_ID = SUPPL2_ID.

How can I do this in SSIS?

Assumptions:


linked servers are not an option, as I want the SSIS package to be portable and not dependent on server environments.
TIA.

-El Salsero

View 5 Replies View Related

How Do I Write SQL Query Accessing Multiple Databases (DBFs)?

Aug 8, 2006

I have several database files, all in the same directory. I want to write SQL statements that access two databases at once. For example, if only one database would be involved, I would write:


SELECT     Test_Source_ID_column, Data_column
INTO            Test_Destination_table
FROM         Test_Sources_table
The above query copies two columns (Test_Source_ID_column and Data_column) from Test_Sources_table into a brand new table called Test_Destination_table.
Now the above query is fine for both the old and new tables being in the same database. But what if Test_Sources_table is in file Old.dbf and I want the new table Test_Destination_table to be in New.dbf?
Both Old.dbf and New.dbf are in the same directory. Therefore, there is no security issue about using ......etcpasswords. I should therefore be able to use relative paths. So, I also want to know how I can do that select on two databases in the same directory without typing long, long paths.
Is there a way to do queries that access multiple database files (all database files being in the exact same directory) AND use relative paths or no paths (and certainly not type a full path)?
NOTE 1: I'm using SQLEXPRESS, therefore do not have the SQL Server 2005 tools. I have Visual Studio 2005 Developer Edition with its tools.
 NOTE 2: One table is accessed through ODBC. The other table is accessed through SQLEXPRESS.
 

View 5 Replies View Related

Delete Query Failes On Some Databases With Internal Server Error 8624

Feb 5, 2008

Hiya,

We've got a strange problem.
We are running on SQL 2000 SP4.
Our structure uses database pairs, we have a Current and a History database so old records that don't change and aren't needed very often are only loaded into memory when needed.

The following query (the names have been changed) deletes the quote from the current database when the order raised from the quote has been moved into the history.




Code Snippet
DELETE FROM t_CurrentUnpaid
FROM db_Mule_History.dbo.t_History INNER JOIN
t_Quote ON
db_Mule_History.dbo.t_History.uid = t_Quote.uid INNER JOIN
t_CurrentUnpaid ON
t_Quote.uid_Parent = t_CurrentUnpaid.uid
where t_CurrentUnpaid.uid_cont != -2






This query runs fine on 4 identical database pairs, on the 5th pair it fails. All these pairs are on the same server, with the same permissions and the exact same structure. Only the data would differ

The error returned is:
Internal server error 8624
level 16 state 1 line 1


We have looked at MS articles, but all that I can find are about bugs fixed in SP1, 2, 3 and 4.
Nothing post SP4 that we are running.

Many thans in advance.

Ian Wilkinson

View 1 Replies View Related

Query 2 Databases In One Query

Nov 30, 2000

In oracle there it is possible to pull data from 2 different databases in 1 query. Does anyone know how to do this in SQL Server? I have tried to do it with a view but I found out that a view will only allow you to pull data from the current database.

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved