这语句为什么会出错呢?

LJDargon 2016-10-18 09:25:56
select case  when count(*)=0 then 0 else score end from (select top 1 score  from ZX_RESULT_INDEXSYSTEM 
where companyCode = '20161017'
and indexCode = '201609261811'
and datepart(month,inspectDate)=10
and datepart(year,inspectDate)=2016
order by inspectDate desc) t

...全文
241 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
中国风 2016-10-18
  • 打赏
  • 举报
回复

SELECT  ISNULL(MAX(score), 0)
FROM    ( SELECT TOP 1
                    score
          FROM      ZX_RESULT_INDEXSYSTEM
          WHERE     companyCode = '20161017'
                    AND indexCode = '201609261811'
                    AND DATEPART(MONTH, inspectDate) = 10
                    AND DATEPART(YEAR, inspectDate) = 2016
          ORDER BY  inspectDate DESC
        ) t;
巨巨巨 2016-10-18
  • 打赏
  • 举报
回复
引用 楼主 LJDargon 的回复:
select case  when count(*)=0 then 0 else score end from (select top 1 score  from ZX_RESULT_INDEXSYSTEM 
where companyCode = '20161017' 
and indexCode = '201609261811' 
and datepart(month,inspectDate)=10
and datepart(year,inspectDate)=2016
order by inspectDate desc) t
你应该这样写: [code=sql][/ select isnull((select top 1 score from ZX_RESULT_INDEXSYSTEM where companyCode = '20161017' and indexCode = '201609261811' and datepart(month,inspectDate)=10 and datepart(year,inspectDate)=2016 order by inspectDate desc),0) code]

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧