SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Iron Speed
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
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  
Old May 2nd, 2008, 08:16 AM
djfubar djfubar is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 378 djfubar User rank is Corporal (100 - 500 Reputation Level)djfubar User rank is Corporal (100 - 500 Reputation Level)djfubar User rank is Corporal (100 - 500 Reputation Level)djfubar User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 13 h 55 m 35 sec
Reputation Power: 5
Query - General - Query Data from 2 Databases

Hi There,

Does anyone know a query data from 2 databases?

Thanks

Reply With Quote
  #2  
Old May 2nd, 2008, 08:43 AM
mehere's Avatar
mehere mehere is offline
Senior Sarcasm Wizardess
Click here for more information.
 
Join Date: Feb 2005
Location: Dreamland
Posts: 12,483 mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)  Folding Points: 10976 Folding Title: Novice Folder
Time spent in forums: 4 Months 3 Weeks 3 Days 21 h 7 m 11 sec
Reputation Power: 1450
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

Reply With Quote
  #3  
Old May 7th, 2008, 08:24 AM
djfubar djfubar is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 378 djfubar User rank is Corporal (100 - 500 Reputation Level)djfubar User rank is Corporal (100 - 500 Reputation Level)djfubar User rank is Corporal (100 - 500 Reputation Level)djfubar User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 13 h 55 m 35 sec
Reputation Power: 5
Quote:
Originally Posted by mehere
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


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.

Reply With Quote
  #4  
Old May 7th, 2008, 09:10 AM
mehere's Avatar
mehere mehere is offline
Senior Sarcasm Wizardess
Click here for more information.
 
Join Date: Feb 2005
Location: Dreamland
Posts: 12,483 mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)  Folding Points: 10976 Folding Title: Novice Folder
Time spent in forums: 4 Months 3 Weeks 3 Days 21 h 7 m 11 sec
Reputation Power: 1450
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.

Reply With Quote
  #5  
Old May 7th, 2008, 09:56 AM
djfubar djfubar is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 378 djfubar User rank is Corporal (100 - 500 Reputation Level)djfubar User rank is Corporal (100 - 500 Reputation Level)djfubar User rank is Corporal (100 - 500 Reputation Level)djfubar User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 13 h 55 m 35 sec
Reputation Power: 5
Quote:
Originally Posted by mehere
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.

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)	

Reply With Quote
  #6  
Old May 7th, 2008, 10:00 AM
mehere's Avatar
mehere mehere is offline
Senior Sarcasm Wizardess
Click here for more information.
 
Join Date: Feb 2005
Location: Dreamland
Posts: 12,483 mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)mehere User rank is General 7th Grade (Above 100000 Reputation Level)  Folding Points: 10976 Folding Title: Novice Folder
Time spent in forums: 4 Months 3 Weeks 3 Days 21 h 7 m 11 sec
Reputation Power: 1450
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.

Reply With Quote
  #7  
Old May 7th, 2008, 10:04 AM
djfubar djfubar is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 378 djfubar User rank is Corporal (100 - 500 Reputation Level)djfubar User rank is Corporal (100 - 500 Reputation Level)djfubar User rank is Corporal (100 - 500 Reputation Level)djfubar User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 13 h 55 m 35 sec
Reputation Power: 5
Quote:
Originally Posted by mehere
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.


gotcha. Ive got an idea on a workaround. thanks for your help.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > Query - General - Query Data from 2 Databases


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway