如何使用 ASP 和 SQL Server 检索来自不同表的两个具有相同名称的字段?

发布于 2025-01-05 16:31:21 字数 684 浏览 1 评论 0原文

首先,如果这是一个奇怪的问题,请原谅我,但这显然不适合我。

我尝试这样做:

    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)

但是,由于 AlertsPeople 都有一个名为 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 do
RS.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

简单 2025-01-12 16:31:21

您可以在 select 语句中使用“as”为列名创建别名:

示例:People.id as PersonID

sql="SELECT Alerts.id, Alerts.id_person, Alerts.type, Alerts.date, 
    People.id as PersonID, People.name, FROM Alerts, People
    WHERE People.name='"& name &"' AND People.id=Alerts.id_person"

这允许您使用:

RS.Fields("PersonID")

You can make an alias for a column name using "as" in your select statement:

example: People.id as PersonID

sql="SELECT Alerts.id, Alerts.id_person, Alerts.type, Alerts.date, 
    People.id as PersonID, People.name, FROM Alerts, People
    WHERE People.name='"& name &"' AND People.id=Alerts.id_person"

This allows you to use:

RS.Fields("PersonID")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文