多部分标识符不起作用

时间:2013-01-21 15:00:23

标签: sql sql-server

不确定以下行为无效:

SELECT Menus.Id, MealTimes.Id, 
  Menus.MealTime_Id, CAST(MealTimes.Name AS TEXT) as MName, 
  CONVERT(VARCHAR(10), Menus.Date, 126) as Date, 
  CAST(Dishes.Name AS TEXT) as Name 
FROM C 
JOIN Menus 
  ON Menus.MealTime_Id=MealTimes.Id 
JOIN MenuDish 
  ON MenuDish.Menus_Id=Menus.Id 
JOIN Dishes 
  ON Dishes.Id=MenuDish.Dishes_Id 
WHERE C.Id=110 AND Menus.Date BETWEEN "2013-01-21" AND "2013-01-25"

现在抛出以下错误:

无法绑定多部分标识符“MealTimes.Name”。

我的加入基本上是这样的:

$this->db->join('Menus', 'Menus.MealTime_Id=MealTimes.Id');
    $this->db->join('MenuDish', 'MenuDish.Menus_Id=Menus.Id');  
    $this->db->join('Dishes', 'Dishes.Id=MenuDish.Dishes_Id');

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

您的查询中没有MealTimes表/别名。