我正在尝试在第一个表中组合两个表(dbo.Dealer_Track_Work)我有一个dealerID这是ID匹配第二个表的ID号(dbo.Dealer_Track_Dealers),我试图让dealerID匹配名称从第二个表和显示而不是数字。有人请告诉我哪里可能出错了吗?
<cffunction name="displayTable" access="public" returntype="query">
<cfset var processTable = ''>
<cfquery name="processTable">
SELECT *
FROM dbo.Dealer_Track_Work, dbo.Dealer_Track_Dealers
WHERE dbo.Dealer_Track_Work.dealerID = dbo.Dealer_Track_Dealers.Name
</cfquery>
<cfreturn processTable>
</cffunction>
<cfoutput>#Name#</cfoutput>
表1
表2
答案 0 :(得分:2)
<cffunction name="displayTable" access="public" returntype="query">
<cfset var processTable = ''>
<cfquery name="processTable">
SELECT name
FROM dbo.Dealer_Track_Work, dbo.Dealer_Track_Dealers
WHERE dbo.Dealer_Track_Work.dealerID = dbo.Dealer_Track_Dealers.id
</cfquery>
<cfreturn processTable>
</cffunction>
<cfoutput>#processTable.Name#</cfoutput>
理想情况下,您将使用ANSI连接语法
<cffunction name="displayTable" access="public" returntype="query">
<cfset var processTable = ''>
<cfquery name="processTable">
SELECT name
FROM dbo.Dealer_Track_Work
INNER JOIN dbo.Dealer_Track_Dealers ON dbo.Dealer_Track_Work.dealerID = dbo.Dealer_Track_Dealers.id
</cfquery>
<cfreturn processTable>
</cffunction>
<cfoutput>#processTable.Name#</cfoutput>