Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 16th, 2004, 04:54 AM
Registered User
 
Join Date: Apr 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default JOINS, Same field name, how to refer?

I'm joining to tables which have filds with the same name.

<%
...
Set rsCustomer = Server.CreateObject("ADODB.Recordset")
sql = "SELECT Cu.Name, Co.Name FROM Customer Cu, Contact Co;"
rsCustomer.Open sql, db, adOpenForwardOnly, adLockOptimistic, adCmdText
....
....
Response.Write rsCustomer("Name")
...
%>

What can I do in order to response.write either the Customer name or the Contact name

 
Old April 16th, 2004, 05:02 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You can alias your column names and then use the alias to refer to them. E.g.:
Code:
Set rsCustomer = Server.CreateObject("ADODB.Recordset")
sql = "SELECT Cu.Name AS CustomerName, Co.Name AS ContactName FROM Customer Cu, Contact Co;"
rsCustomer.Open sql, db, adOpenForwardOnly, adLockOptimistic, adCmdText
....
....
Response.Write("Customer: " & rsCustomer("CustomerName")
Response.Write("Contact: " & rsCustomer("ContactName")
HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: B.L.U.R.E.M.I. by Blur (Track 6 from the album: 13)

 
Old April 16th, 2004, 05:49 AM
Registered User
 
Join Date: Apr 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks! That one solved the problem! Now, I'm happy!

Best regards
Sigbjorn

Quote:
quote:Originally posted by Imar
 Hi there,

You can alias your column names and then use the alias to refer to them. E.g.:
Code:
Set rsCustomer = Server.CreateObject("ADODB.Recordset")
sql = "SELECT Cu.Name AS CustomerName, Co.Name AS ContactName FROM Customer Cu, Contact Co;"
rsCustomer.Open sql, db, adOpenForwardOnly, adLockOptimistic, adCmdText
....
....
Response.Write("Customer: " & rsCustomer("CustomerName")
Response.Write("Contact: " & rsCustomer("ContactName")
HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: B.L.U.R.E.M.I. by Blur (Track 6 from the album: 13)






Similar Threads
Thread Thread Starter Forum Replies Last Post
Refer to Rows and Columns RayL Access VBA 3 May 23rd, 2007 09:13 AM
Refer to a cell with a DataView bufanator VB.NET 2002/2003 Basics 2 January 11th, 2007 04:55 PM
Refer to Textbox.value in report jmurdock BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 3 September 24th, 2004 08:32 AM
how to refer another form khautinh General .NET 2 March 17th, 2004 01:29 PM
How to refer assemblies which are in GAC ? kishore_peddi C# 0 October 12th, 2003 09:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.