Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: ASP, SQL and connecting/linking databases (not tables)


Message #1 by "Bengt" <asp@k...> on Tue, 9 May 2000 18:48:35
Hello!



I have two tables which exists in two different SQL Server databases (mdf). 

The two tables, which present information about books,  have one column 

(field) which is same for both. Now I want to present information about the 

books on an ASP-page, where the information from the two tables are 

combined.



In Access I just linked the two tables in an Access-database and then run 

an query (SELECT dbo_Prod.Descr, dbo_LibBooks.Author, dbo_LibBooks.Subject 

FROM dbo_Prod INNER JOIN dbo_LibBooks ON dbo_Prod.Descr = 

dbo_LibBooks.Title;). Can I do something similiar with my two tables from 

my two SQL databases using ASP and SQL? (I understand that it ´would be 

better to have the two tables in the same database, but due to certain 

reasons...)



Regards

Bengt

Message #2 by "Jessica Chen" <jchen@g...> on Tue, 9 May 2000 16:10:03 -0400
You can use the following code:

	select * from database1..table1 t1, datbase2..table2 t2 where t1.col 

t2.col



Jessica



-----Original Message-----

From: Bengt 

Sent: Tuesday, May 09, 2000 6:49 PM

To: ASP Databases

Subject: [asp_databases] ASP, SQL and connecting/linking databases (not

tables)





Hello!



I have two tables which exists in two different SQL Server databases (mdf

).

The two tables, which present information about books,  have one column

(field) which is same for both. Now I want to present information about t

he

books on an ASP-page, where the information from the two tables are

combined.



In Access I just linked the two tables in an Access-database and then run

an query (SELECT dbo_Prod.Descr, dbo_LibBooks.Author, dbo_LibBooks.Subjec

t

FROM dbo_Prod INNER JOIN dbo_LibBooks ON dbo_Prod.Descr =3D

dbo_LibBooks.Title;). Can I do something similiar with my two tables from

my two SQL databases using ASP and SQL? (I understand that it =B4would be

better to have the two tables in the same database, but due to certain

reasons...)



Regards

Bengt

Message #3 by Kevin D Riggs <kevin.riggs@p...> on Tue, 09 May 2000 16:17:04 -0400
Bengt,



	The first thing that comes to mind is to create a stored procedure and

fire it off using an ADODB.Command object.  Set the object.CommandType 

adStoredCommand (I think).  Don't have my books with me right now so I

can't tell you for sure.  That way, you save some of the processor overhead

in creating the recordset since its handled in SQL Server (which is

optimized to perform JOINs, etc).  Here is my best estimation without my

texts in front of me:



>>>>>>>>>>>>>>>>Code
Snippet<<<<<<<<<<<<<<<<<<<



Dim cmdBooks, recBooks



Set cmdBooks = Server.CreateObject("ADODB.Command")

Set recBooks = Server.CreateObject("ADODB.Recordset")



cmdBooks.ActiveConnection = "DSN=yourDSN;UID=yourUserID;PWD=yourPassWorD;"

cmdBooks.CommandType = adStoredCommand



cmdBooks.CommandText = storedProcedureName



Set recBooks = cmdBooks.Execute



While Not recBooks.EOF



	Response.Write "Blah <br>" & vbCrLf

	Response.Write "Blah <br>" & vbCrLf

	Response.Write "Blah <br>" & vbCrLf



	recBooks.MoveNext



Wend





Set recBooks = Nothing

Set cmdBooks = Nothing



>>>>>>>>>>>>>>>End
Code<<<<<<<<<<<<<<<<<<<







KD





Kevin D Riggs



kevin.riggs@p...

AOL IM - "wsi tn"



Senior Network Administrator & Webmaster

Rhea County

Board of Education



http://www.rhea.k12.tn.us/

http://www.rheacounty.org/


  Return to Index