Re: Query two databases with asp
- From: "Bob Barrows [MVP]" <reb01501@xxxxxxxxxxxxxxx>
- Date: Wed, 12 Mar 2008 11:50:46 -0400
Well, when you get back to it, here is a view and stored procedure that
accepts a school and/or a parish returns all the user fields whose names
you provided:
CREATE VIEW SchoolsUsers AS
SELECT s.Parish, s.School, s.Principal, s.address SchoolAddress, s.city
SchoolCity, s.zip SchoolZip,
u.ID UserID, firstname, lastname, u.address UserAddress, u.city
UserCity, u.CompanyName
FROM DB1..Schools s inner join DB2..Users u
ON s.ID = CAST(u.CompanyName AS INT)
go
CREATE PROCEDURE DB2..GetUsersBySchoolorParish (
@School nvarchar(255)
,@Parish nvarchar(255)) AS
SET NOCOUNT ON
IF @School > '' AND @Parish > ''
SELECT UserID, firstname, lastname,UserAddress,UserCity,CompanyName
FROM SchoolsUsers
WHERE Parish = @Parish AND School = @School
ELSE
BEGIN
IF @School > ''
SELECT UserID, firstname, lastname,UserAddress,
UserCity,CompanyName
FROM SchoolsUsers
WHERE School = @School
ELSE
SELECT UserID, firstname, lastname,UserAddress,
UserCity,CompanyName
FROM SchoolsUsers
WHERE Parish = @Parish
END
To retrieve results from this in ASP, i would do this:
<%
dim cn, rs, school, parish, sHTML, fld
school = Request.Form("school") ' or Querystring
parish= Request.Form("parish") ' or Querystring
set cn=createobject("adodb.connection")
cn.open "provider=sqloledb;data source=sqlservername;" & _
"user id = xxxxx;password=xxxxx;initial catalog=DB2"
set rs=createobject("adodb.recordset")
cn.GetUsersBySchoolorParish school, parish, rs
if not rs.eof then
sHTML = "<table><tr>"
for each fld in rs.fields
sHTML=sHTML & "<th>" & fld.name & "</th>"
next
sHTML=sHTML & "</tr><tr><td>"
sHTML = sHTML & _
rs.GetString(,,"</td><td>","</td></tr><tr><td>")
sHTML = left(sHTML,len(sHTML) - 8) & "</table>"
response.write sHTML
else
response.write "no users returned"
end if
%>
dusty wrote:
Thanks for explaining the precision and scale. I was a little unsure
about it, that's why I didn't reply to it.
The CompanyName field actually displays a numeric value that
corresponds to the ID field. I appreciate all of the information you
have provided and I'm sorry to have taken up much of your time. I
think I'll just put this project on hold for now.
Thanks again.
"Bob Barrows [MVP]" wrote:
dusty wrote:
DB1..School
ID - INT(data type) - 4 (length) - PKey
Parish - nvarchar - 255
School - nvarchar - 255
DB2..Users
ID - numeric(data type) - 9 (length)
A numeric column (also known as a "decimal" column) has both a
precision (total number of digits allowed) and a scale (number of
digits used for the decimal portion). I can do without this
information in this particular situation, but you should make a
point of providing it when asked in the future.
FirstName - varchar - 50
LastName - varchar - 50
Address - varchar - 50
City - varchar - 25
State - varchar - 10
Zip - varchar - 10
CompanyName - varchar - 50
Username - varchar - 50 - PKey
The CompanyName field in the users table under DB2 is the ID field
of DB1.
That is not possible. An INT column cannot be used to link to a
varchar column ... unless you have a varchar column containing
integer data ... is that the case? I know you said you did not
create the databases, but this seems nonsensical to me. Anyways, if
this is the case, it will make your joins very inefficient due to
the necessity of making datatype conversions on the fly.
What version of SQL Server is this? Can you modify the design of
DB2..Users? Perhaps add a calculated field to it?
It is taking very long to gather the requirements for this task.
Given that I have my own job, I am not going to be able to devote a
lot of time to this. Perhaps you should consider hiring a consultant
to do this for you ...
Here is some information about what information needs to be provided
to enable people (including a consultant if you go that route) to
help you with database-related problems:
http://www.aspfaq.com/etiquette.asp?id=5006
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get
a quicker response by posting to the newsgroup.
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
.
- Follow-Ups:
- Re: Query two databases with asp
- From: dusty
- Re: Query two databases with asp
- References:
- Re: Query two databases with asp
- From: Bob Barrows [MVP]
- Re: Query two databases with asp
- From: Bob Barrows [MVP]
- Re: Query two databases with asp
- From: dusty
- Re: Query two databases with asp
- From: Bob Barrows [MVP]
- Re: Query two databases with asp
- From: dusty
- Re: Query two databases with asp
- Prev by Date: Re: Query two databases with asp
- Next by Date: Re: Query two databases with asp
- Previous by thread: Re: Query two databases with asp
- Next by thread: Re: Query two databases with asp
- Index(es):
Relevant Pages
|
Loading