我有关于sql内部连接语法的错误,如此
“SELECT子句中的错误:'。'附近的表达式。 缺少FROM子句。 SELECT子句中的错误:','附近的表达式。 无法解析查询文本。 “
这是我的查询
SELECT VS_OrderItem.ARCIM_RowId, VS_OrderItem.ARCIM_Code, VS_OrderItem.ARCIM_Desc, ARC_Alias.ALIAS_Desc VS_OrderItem.ARCIM_Abbrev, VS_OrderItem.ARCIM_EffDate, VS_OrderItem.ARCIM_EffDateTo, VS_OrderItem.ARCIM_OrderOnItsOwn, ARC_BillSub.ARCSG_RowId, VS_OrderItem.ARCIC_RowId
FROM VS_OrderItem, ARC_BillSub
INNER JOIN ARC_Alias
ON VS_OrderItem.ARCIM_RowId = ARC_Alias.ALIAS_ARCIM_DR
WHERE( VS_OrderItem.ARCSG_Code = ARC_BillSub.ARCSG_Code)
GROUP BY VS_OrderItem.ARCIM_RowId
我是否遗漏了有关此查询的内容。非常感谢。
答案 0 :(得分:0)
似乎只有ARC_Alias.ALIAS_Desc和VS_OrderItem.ARCIM_Abbrev之间缺少逗号,因此SQL Server将VS_OrderItem.ARCIM_Abbrev视为别名,其中不允许使用其间的点。如果您确实想使用VS_OrderItem.ARCIM_Abbrev作为别名,则应将其放在括号中:ARC_Alias.ALIAS_Desc [VS_OrderItem.ARCIM_Abbrev]
答案 1 :(得分:0)
您缺少与表ARC_BillSub
的联接。您的查询应该是
SELECT VS_OrderItem.ARCIM_RowId, VS_OrderItem.ARCIM_Code, VS_OrderItem.ARCIM_Desc, ARC_Alias.ALIAS_Desc VS_OrderItem.ARCIM_Abbrev, VS_OrderItem.ARCIM_EffDate, VS_OrderItem.ARCIM_EffDateTo, VS_OrderItem.ARCIM_OrderOnItsOwn, ARC_BillSub.ARCSG_RowId, VS_OrderItem.ARCIC_RowId
FROM VS_OrderItem INNER JOIN ARC_BillSub on VS_OrderITem.columnName = ARC_BillSub.columnName
INNER JOIN ARC_Alias
ON VS_OrderItem.ARCIM_RowId = ARC_Alias.ALIAS_ARCIM_DR
WHERE( VS_OrderItem.ARCSG_Code = ARC_BillSub.ARCSG_Code)
GROUP BY VS_OrderItem.ARCIM_RowId
答案 2 :(得分:0)
您在ARC_Alias.ALIAS_Desc和VS_OrderItem.ARCIM_Abbrev列以及混合联接类型之间缺少逗号
SELECT VS_OrderItem.ARCIM_RowId,
VS_OrderItem.ARCIM_Code,
VS_OrderItem.ARCIM_Desc,
ARC_Alias.ALIAS_Desc ,--this is the one you missed
VS_OrderItem.ARCIM_Abbrev,
VS_OrderItem.ARCIM_EffDate,
VS_OrderItem.ARCIM_EffDateTo,
VS_OrderItem.ARCIM_OrderOnItsOwn,
ARC_BillSub.ARCSG_RowId,
VS_OrderItem.ARCIC_RowId
FROM VS_OrderItem INNER JOIN
ARC_BillSub on VS_OrderItem.<some column name> = ARC_BillSub.<some column name>
INNER JOIN ARC_Alias
ON VS_OrderItem.ARCIM_RowId = ARC_Alias.ALIAS_ARCIM_DR
WHERE( VS_OrderItem.ARCSG_Code = ARC_BillSub.ARCSG_Code)
GROUP BY VS_OrderItem.ARCIM_RowId
答案 3 :(得分:0)
重新格式化以使用一致的连接类型并添加了缺少的逗号,您的查询将看起来像这样。您面临的最大挑战是格式化。很难看出何时将所有列填充到一行上。
SELECT o.ARCIM_RowId
,o.ARCIM_Code
,o.ARCIM_Desc
,a.ALIAS_Desc
,o.ARCIM_Abbrev
,o.ARCIM_EffDate
,o.ARCIM_EffDateTo
,o.ARCIM_OrderOnItsOwn
,b.ARCSG_RowId
,o.ARCIC_RowId
FROM VS_OrderItem o
INNER JOIN ARC_BillSub b on o.ARCSG_Code = b.ARCSG_Code
INNER JOIN ARC_Alias a ON o.ARCIM_RowId = a.ALIAS_ARCIM_DR
GROUP BY o.ARCIM_RowId