代码之家  ›  专栏  ›  技术社区  ›  corsiKa

SQL语法问题(左联接)

  •  2
  • corsiKa  · 技术社区  · 14 年前

    所以我对一个查询有问题,我真的不知道在哪里。注释放在语法错误所在的位置。这个查询要大得多,我试着缩短它以生成一个有效但更整洁的查询。

    这将使用ODBC连接到进度数据库。我听说它使用严格的SQL-92。

    SELECT itemcust."item-cust", 
           itemcust."cust-no", 
           corptreeCust.code 
    
    FROM      pub."item-cust" itemcust 
    JOIN      pub.customer cust 
    left join pub.salesstructcustomer struct 
         on ( struct."corp-cust-type" = cust."corp-cust-type" 
          and struct."corp-cust-num" = cust."corp-cust-num" 
         ) 
    left join pub.corptree corptreeCust 
          on ( corptreeCust.uid = struct.corptreeid /* program says SQL Syntax error here */
           and corptreeCust.category = 'store' 
          ) 
    
    where ( itemcust."in-entity" = {$entity} or itemcust."in-entity" = '*') 
      and itemcust."item-no" = {$itemno} 
      and ( itemcust."cust-no" = {$custno} or itemcust."cust-no" = '*') 
      and cust."cust-no" = {$custno}
    

    谢谢!

    4 回复  |  直到 14 年前
        1
  •  6
  •   Joe Stefanelli    14 年前

    您的表别名 pub.salesstructcustomer struct 不是 structc 在联接中引用。

        2
  •  5
  •   Onite    14 年前

    是打字错误吗?看起来它是在看structc而不是struct,除非我遗漏了什么。

        3
  •  3
  •   Kevin O'Donovan    14 年前

    在CUST和ITEMCUST之间似乎没有ON子句。这肯定会使解析器混淆,从而在查询中进一步抛出错误。

        4
  •  0
  •   corsiKa    14 年前

    首先,我感谢你的回答。没有从句的事实是一个严重的问题,但实际上不是真正的问题。

    问题其实是 uid 是个保留字,我必须做到 corptreeCust.\"uid\"

    =(

    推荐文章