Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL错误-无法绑定多部分标识符_Sql_Sql Server 2008 - Fatal编程技术网

SQL错误-无法绑定多部分标识符

SQL错误-无法绑定多部分标识符,sql,sql-server-2008,Sql,Sql Server 2008,我正在尝试以这种格式获得数据的水平输出 查询是: SELECT RDT1.County_Name ,RDT1.DistributionNumber as Dist_No ,RDT1.Vac_Allocated ,RDT1.Priority,RDT2.DistributionNumber as Dist_No ,RDT2.Vac_Allocated as Vac_Allocated ,RDT3.DistributionNumber as

我正在尝试以这种格式获得数据的水平输出

查询是:

SELECT RDT1.County_Name
      ,RDT1.DistributionNumber as Dist_No
      ,RDT1.Vac_Allocated
      ,RDT1.Priority,RDT2.DistributionNumber as Dist_No
      ,RDT2.Vac_Allocated as Vac_Allocated
      ,RDT3.DistributionNumber as Dist_No
      ,RDT3.Vac_Allocated as Vac_Allocated 
FROM Result_Distribution_Table AS RDT1
    ,Result_Distribution_Table AS RDT2
    ,Result_Distribution_Table AS RDT3 
WHERE RDT1.County_Name = RDT2.County_Name AND
      RDT1.DistributionNumber = 1 AND 
      RDT2.DistributionNumber = 2 AND 
      RDT3.DistributionNumber = 3 AND 
      RDT1.County_Name = RDT3.County_Name 
WHERE Solution_id= "10" 
当我执行这个查询时,我得到一个响应

味精4104,第16级,状态1,第1行
无法绑定多部分标识符“解决方案id”

Solution\u id
Result\u Distribution\u表
中的一列


请帮助说明我做错了什么以及解决方案是什么?

每个查询只能有一个
WHERE
子句。另外,请避免使用旧式连接,而应使用
JOIN
注意:
解决方案id
列填写正确的表格

SELECT RDT1.County_Name
      ,RDT1.DistributionNumber as Dist_No
      ,RDT1.Vac_Allocated
      ,RDT1.Priority,RDT2.DistributionNumber as Dist_No
      ,RDT2.Vac_Allocated as Vac_Allocated
      ,RDT3.DistributionNumber as Dist_No
      ,RDT3.Vac_Allocated as Vac_Allocated 
FROM Result_Distribution_Table RDT1 JOIN  Result_Distribution_Table RDT2
      ON RDT1.County_Name = RDT2.County_Name JOIN Result_Distribution_Table RDT3 
      ON RDT1.County_Name = RDT3.County_Name
WHERE RDT1.DistributionNumber = 1 AND 
      RDT2.DistributionNumber = 2 AND 
      RDT3.DistributionNumber = 3 AND 
      [...].Solution_id= "10"
添加:刚刚注意到您正在使用同一个表3次如果是这样您可以得到与相同的结果

SELECT County_Name
          ,DistributionNumber as Dist_No
          ,Vac_Allocated
          ,Priority,RDT2.DistributionNumber as Dist_No
          ,Vac_Allocated as Vac_Allocated
          ,DistributionNumber as Dist_No
          ,Vac_Allocated as Vac_Allocated 
FROM Result_Distribution_Table 
WHERE DistributionNumber IN (1,2,3) AND
          Solution_id= "10"

问题是因为查询中没有表:


您似乎忘记在查询中包含该表。

您的意思是在查询中包含两个
WHERE
语句吗?-这种旧式的逗号分隔表列表样式在ANSI-92 SQL标准(20年前!)。请停止使用它第二个查询有一个孤立的
RDT2
表引用,不要介意这样一个事实,即您无论如何不能从一个表引用中获得相同的输出(或者没有类似
PIVOT
)。