我该如何加入这些表?

时间:2012-10-16 14:14:08

标签: sql join inner-join

我有一个连接5个表的SQL语句,但我认为我必须正确加入它们。我有一个asp.net表单,允许通过复选框和下拉列表输入,所以我正在基于UI构建SQL内部代码。

搜索条件将包括3个不同表格中的字段。我得到的错误是

  

无法绑定多部分标识符“openingReq.bgChk”。

我觉得我的加入一定是问题所在,但我不确定如何更改它们才能使其发挥作用。

这是SQL语句

  SELECT COMPANY.NAME, 
       SITE.NAME, 
       OPENING.JOBTITLE, 
       ( OPENINGSCHED.WEEKLYHOURSLOW + '-' 
         + OPENINGSCHED.WEEKLYHOURSHIGH )                   AS weeklyHours, 
       ( OPENINGCOMP.WAGELOW & '-' & OPENINGCOMP.WAGEHIGH ) AS payRange 
FROM   COMPANY 
       INNER JOIN [SITE] 
               ON COMPANY.ORGID = SITE.ORGID 
       INNER JOIN OPENING 
               ON SITE.SITEID = OPENING.SITEID 
       INNER JOIN OPENINGSCHED 
               ON OPENING.OPENINGID = OPENINGSCHED.OPENINGID 
       INNER JOIN OPENINGCOMP 
               ON OPENINGSCHED.OPENINGID = OPENINGCOMP.OPENINGID 
WHERE  OPENING.JOBORWE = 'Job' 
       AND OPENING.OCCUPATIONCODE = 59 
       AND COMPANY.SECTORCODE = 202 
       AND OPENING.ONBUSROUTE = 1 
       AND ( OPENING.LANGCODE = 1 
              OR OPENING.LANGCODE = 7 
              OR OPENING.LANGCODE = 22 ) 
       AND OPENING.TIER = 1 
       AND OPENINGREQ.BGCHK = 1 
       AND OPENINGREQ.MINEXP = 'no minimum experience' 
       AND OPENINGREQ.MINED = 'no minimum education' 

4 个答案:

答案 0 :(得分:1)

您的查询中没有名为“openingReq”的表或别名。

答案 1 :(得分:1)

我正在查看您的查询,但找不到OPENINGREQ表的联接 这可以解释为什么SQL无法绑定它!

答案 2 :(得分:0)

我无法在任何地方看到JOIN中的表openingReq - 而是WHERE子句......

答案 3 :(得分:0)

您的上下文中不存在

OPENINGREQ。将其替换为正确的表名或别名:

   AND OPENINGREQ.BGCHK = 1 
   AND OPENINGREQ.MINEXP = 'no minimum experience' 
   AND OPENINGREQ.MINED = 'no minimum education'