"当子查询没有引入EXISTS"时,只能在选择列表中指定一个表达式。错误

时间:2014-12-18 09:46:43

标签: mysql sql


我正在努力让以下查询工作:

我写了这个存储过程:

IF (@Mode='CurrentRootList') 
BEGIN
SELECT ROW_NUMBER() OVER
  (
        ORDER BY emp1.EmployeeName ASC
  )AS RowNumber 
  ,emp1.empid 
  ,emp1.EmployeeName
  ,(SELECT * FROM [Mobile_Locations] mloc where emp1.MobileID=mloc.MobileID AND mloc.LocationTime = DATEDIFF(MINUTE, mloc.LocationTime , CURRENT_TIMESTAMP)) as LocationTime
  ,emp1.ArrivalTime
  ,emp1.DeviceStatus      
 INTO #CurrentDateRootList
  FROM [EMP_Locations] emp1 join [Root] root1 ON emp1.EmployeeName = root1.EmployeeName  where (CURRENT_TIMESTAMP BETWEEN root1.StartDate AND root1.EndDate)


  SELECT @RecordCount = COUNT(*)
  FROM #CurrentDateRootList

  SELECT * FROM #CurrentDateRootList
  WHERE RowNumber BETWEEN(@PageIndex -1) * @PageSize + 1 AND(((@PageIndex -1) * @PageSize + 1) + @PageSize) - 1

  DROP TABLE #CurrentDateRootList
END

如何解决此错误。 请帮帮我。

1 个答案:

答案 0 :(得分:0)

填充LocationTime的子查询可能返回多行。您应该为该子查询添加LIMIT 1。

编辑:并确保子查询只返回一列(注意* ..)。