使用ASP from SQL从具有相同id的相同列名的多个表中得到的结果
我需要一些帮助编写ASP从SQL获取数据 我有三张桌子——电脑、显示器和监视器2。Monitor2表是Monitor表(包括数据)的精确克隆。(别问我为什么,在我来这里之前就做了) 从PC表中使用的列 PC_ID、名称(加上一些其他名称,但此处不相关) 监视器和监视器2表中的列 监视器ID、名称、尺寸、PC ID、品牌、型号 基本上,我需要提取结果来填充一个表,该表显示了哪个PC.Name具有哪个Monitor.Name、Monitor2.Name和其他属性 例如 这就是我目前所拥有的使用ASP from SQL从具有相同id的相同列名的多个表中得到的结果,sql,sql-server,asp-classic,Sql,Sql Server,Asp Classic,我需要一些帮助编写ASP从SQL获取数据 我有三张桌子——电脑、显示器和监视器2。Monitor2表是Monitor表(包括数据)的精确克隆。(别问我为什么,在我来这里之前就做了) 从PC表中使用的列 PC_ID、名称(加上一些其他名称,但此处不相关) 监视器和监视器2表中的列 监视器ID、名称、尺寸、PC ID、品牌、型号 基本上,我需要提取结果来填充一个表,该表显示了哪个PC.Name具有哪个Monitor.Name、Monitor2.Name和其他属性 例如 这就是我目前所拥有的 sqlq
sqlq = "SELECT PC.PC_ID, PC.PC_Name, PC.CPU, PC.RAM, PC.Make, PC.Model, PC.Date, Monitor2.Name as mon_name2, Monitor2.Size as mon_size2, Monitor.Name as mon_name, Monitor.Size as mon_size FROM Monitor right JOIN PC ON Monitor.PC_ID = PC.PC_ID FROM Monitor2 right JOIN PC ON Monitor2.PC_ID = PC.PC_ID
set rs = conn.execute(sqlq)
if rs.eof or rs.bof then
response.write("No Records Found")
else
'count how many records have been returned
count=0
rs.movefirst
pcname=""
do while not rs.eof
if pcname <> rs("PC_Name") then
count=count+1
end if
pcname=rs("PC_Name")
rs.movenext
loop
Response.write("<font size='2'>No. of records returned:" & count & " </font>")
rs.movefirst
pcname=""
%>
<%if not PrintF then %>
如果不是那样的话,我会得到
无法绑定多部分标识符“Monitor2.Name”
或者其他一些不正确的语法错误
为您的帮助干杯
FROM Monitor right JOIN PC ON Monitor.PC_ID=PC.PC_ID FROM Monitor2
从中取出第二个。。这是监视器2中的
这就给你留下了
SELECT PC.PC_ID,
PC.PC_Name,
PC.CPU,
PC.RAM,
PC.Make,
PC.Model,
PC.Date,
Monitor2.Name AS mon_name2,
Monitor2.Size AS mon_size2,
Monitor.Name AS mon_name,
Monitor.Size AS mon_size
FROM Monitor
RIGHT JOIN PC ON Monitor.PC_ID = PC.PC_ID
RIGHT JOIN PC ON Monitor2.PC_ID = PC.PC_ID
这是没有道理的,也是不正确的。我想你是想做这样的事
SELECT PC.PC_ID,
PC.PC_Name,
PC.CPU,
PC.RAM,
PC.Make,
PC.Model,
PC.Date,
Monitor2.Name AS mon_name2,
Monitor2.Size AS mon_size2,
Monitor.Name AS mon_name,
Monitor.Size AS mon_size
FROM PC
LEFT JOIN Monitor ON Monitor.PC_ID = PC.PC_ID
LEFT JOIN Monitor2 ON Monitor2.PC_ID = PC.PC_ID
如果你在监视器或监视器2中有一台电脑ID的多条记录,你会被复制。JamieD77因为你真的很有帮助,你能看看我刚才提出的其他问题吗?需要重新审视一下。Thx-
Microsoft OLE DB Provider for SQL Server error '80040e14'
Incorrect syntax near the keyword 'FROM'.
/PCs/SearchResult.asp, line 31
SELECT PC.PC_ID,
PC.PC_Name,
PC.CPU,
PC.RAM,
PC.Make,
PC.Model,
PC.Date,
Monitor2.Name AS mon_name2,
Monitor2.Size AS mon_size2,
Monitor.Name AS mon_name,
Monitor.Size AS mon_size
FROM Monitor
RIGHT JOIN PC ON Monitor.PC_ID = PC.PC_ID
RIGHT JOIN PC ON Monitor2.PC_ID = PC.PC_ID
SELECT PC.PC_ID,
PC.PC_Name,
PC.CPU,
PC.RAM,
PC.Make,
PC.Model,
PC.Date,
Monitor2.Name AS mon_name2,
Monitor2.Size AS mon_size2,
Monitor.Name AS mon_name,
Monitor.Size AS mon_size
FROM PC
LEFT JOIN Monitor ON Monitor.PC_ID = PC.PC_ID
LEFT JOIN Monitor2 ON Monitor2.PC_ID = PC.PC_ID