|
|
|||||||||
|
|||||||||
|
|||||||||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
Query - General - Query Data from 2 Databases
Hi There,
Does anyone know a query data from 2 databases? Thanks |
|
#2
|
||||
|
||||
|
if you're querying data from a another database, you just need to use the DB name, owner name and table name in the query. for example:
Code:
SELECT field1, field2, column1 FROM tbl_TableName t1 INNER JOIN dbName.dbo.tbl_TableName2 t2 ON t1.field1 = t2.column2
__________________
Come JOIN the party!!! Quote of the Month: Trouble: Luck can't last a lifetime unless you die young. Questions to Ponder: Do cemetery workers prefer the graveyard shift? iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm") copyright© 2008 sbenj69 |
|
#3
|
|||
|
|||
|
Quote:
Thanks for the example. Ive got the query to work in query analyzer but not on my asp page. the following is the sql Code:
SELECT username FROM employee t1 INNER JOIN ITSUPPORTSLA.dbo.caselist t2 ON t1.username = t2.contact WHERE username = 'test' GROUP BY username im executing the connection which relates to the employee table Code:
SET rsPurchase = objConn.Execute(SQLQuery) this is the error message im getting Code:
Error Type: Microsoft OLE DB Provider for SQL Server (0x80040E37) Invalid object name 'ITSUPPORTSLA.dbo.caselist'. Is it possible to excute multiple connections? Any help would be great. |
|
#4
|
||||
|
||||
|
is the logon you're using in your ASP page have access to the other Database? if not, then it won't work. yes you can have multiple connections in your page and execute them, but not when you're using a join like that.
|
|
#5
|
|||
|
|||
|
Quote:
ive got connections to both dbs Code:
Set objConnection=Server.CreateObject("ADODB.Connection")
objConnection.Open Application("ITSupportSLA")
Set objConn=Server.CreateObject("ADODB.Connection")
objConn.Open Application("MainDb")
The problem is that im only executing one of the connections for the sql query?? Code:
SET rsPurchase = objConn.Execute(SQLQuery) |
|
#6
|
||||
|
||||
|
that's what i'm saying ... you can't use 2 connections with a JOIN query. if your databases require two different logons, this is not going to work. you would need to query from the first database and then run subsequent queries on the second. the only way the join will work, is if the logon and password for database1 also has access to database2.
|
|
#7
|
|||
|
|||
|
Quote:
gotcha. Ive got an idea on a workaround. thanks for your help. |
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > Query - General - Query Data from 2 Databases |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|
|