如何使用 ASP 和 SQL Server 检索来自不同表的两个具有相同名称的字段?
首先,如果这是一个奇怪的问题,请原谅我,但这显然不适合我。
我尝试这样做:
sql="SELECT Alerts.id, Alerts.id_person, Alerts.type, Alerts.date,
People.id, People.name, FROM Alerts, People
WHERE People.name='"& name &"' AND People.id=Alerts.id_person"
set RS=oADO.Execute(sql)
但是,由于 Alerts 和 People 都有一个名为 id 的字段,因此我在引用它们时遇到问题。 我不被允许这样做 RS.Fields("Alerts.id")
或 RS.Fields("People.id")
,仅限 RS.Fields("id")
代码> 这不允许我选择我想要使用的字段(实际上我需要使用它们)。
我无法更改 DDBB 的结构(它不是我制作的)。
有什么提示我可以做什么吗?非常感谢。
我忘了说这将选择许多条目,我将用
While not RS.EOF
Lorep Ipsum
Wend
First of all, forgive me if this is a weird question, but it clear isn't for me.
I try to do this:
sql="SELECT Alerts.id, Alerts.id_person, Alerts.type, Alerts.date,
People.id, People.name, FROM Alerts, People
WHERE People.name='"& name &"' AND People.id=Alerts.id_person"
set RS=oADO.Execute(sql)
But, as both Alerts and People have a field named id, I have a problem refering to them.
I'm not allowed to doRS.Fields("Alerts.id")
or RS.Fields("People.id")
, only RS.Fields("id")
And that doesn't let me choose wich field I want to use (and actually I'd need to use both of them).
I cannot change the structure of the DDBB (it hasn't been made by me).
Any hint of what I can do? Thank you very much.
I forgot to say that this is going to select many entries, and i'll play with them with a
While not RS.EOF
Lorep Ipsum
Wend
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在 select 语句中使用“as”为列名创建别名:
示例:
People.id as PersonID
这允许您使用:
You can make an alias for a column name using "as" in your select statement:
example:
People.id as PersonID
This allows you to use: