日期:2014-05-18  浏览次数:20622 次

同样的sql语句,当数据库在本机时正确,在另外的服务器上就出错?
如题,sql 如下:
SELECT 业务号=Upper(Left(JobNo,2)),年份=Cast(Substring(JobNo,3,2) as char),
  count(case when Cast(Substring(JobNo,5,2) as int)=1 then Left(JobNo,2) else null end) as [1],
  count(cast(Substring(JobNo,5,2) as int)) as 合计  
  FROM JobSheet_SI  
  WHERE AcceptDate >'2005' and (Cast(Substring(JobNo,3,2) as CHAR)>'04') and Upper(Substring(JobNo,1,2))<>'YR' and Upper(Substring(JobNo,1,2))<>'SX' and Upper(Substring(JobNo,1,2))<>'Y0'  
  GROUP BY Left(JobNo,2),Cast(Substring(JobNo,3,2) as char)  
  ORDER BY 业务号,年份 

当数据库还原到本机,运行正确;但数据库在局域网的另外一台计算机,就出错:

JobNo 不在聚合函数或group by 子句内(大意如此)

------解决方案--------------------
--try

GROUP BY Upper(Left(JobNo,2)),Cast(Substring(JobNo,3,2) as char)