0

这是我正在做的事情的简化版本,但我什么也做不了。该语句在“ERR”之后给我一个没有逗号的错误。我希望专栏是“月”,我认为这会起作用,但我遇到了很多麻烦。谢谢你的帮助!

   选择
 a.POL_PRI_RSK_ST_CD,a.MASTER_COMPANY_NBR,

案子

当 a.char046 为 NULL 时,'ERR'

当 a.char046 > '010' 然后 '11+'

否则 a.char046 以 Policy_Years 结尾,

a.Last7Days,a.Last30Days,a.Last90Days

从报告内部连接

存储库 b

在 a.RECORD_ID = b.RECORD_ID

其中 a.POL_OGN_EFF_DT >= '2008-11-01'

通过...分组

a.POL_PRI_RSK_ST_CD,a.MASTER_COMPANY_NBR,

案子

当 a.char046 为 NULL 时,'ERR'

当 a.char046 > '010' 然后 '11+'

否则 a.char046 以 Policy_Years 结尾,

a.Last7Days,a.Last30Days,a.Last90Days
4

8 回答 8

2

注意:这是问题评论中调试会话的结果。

错误Incorrect syntax near the keyword 'as'.是由as Policy_YearsinGROUP BY子句引起的。不允许asGROUP BY子句中使用。

于 2010-02-02T15:35:56.390 回答
2

尝试不带逗号...示例。

select  
   case 
      when a.month is NULL then 'ERR'
      when a.month > '011' then '12' 
      else a.month 
   end as Month, 
   a.Last7Days 
from ... 
于 2010-02-02T14:58:40.180 回答
0

您不能ASGROUP BY. 该表达式应与您的 SELECT 中的表达式匹配,但不包含别名。

于 2010-02-02T15:31:57.703 回答
0

解决有关“多部分标识符”日的新错误消息,

dayyear列在表中吗?查询中的 From 之后是什么?您是否在此将多个表连接在一起?请显示整个查询?

好的,根据您编辑的问题,(您不能在 Group By 中使用别名)试试这个:

select a.POL_PRI_RSK_ST_CD, 
  a.MASTER_COMPANY_NBR,
  case when a.char046 is NULL then 'ERR'
       when a.char046 > '010' then '11+'
       else a.char046 end as Policy_Years,
  a.Last7Days, a.Last30Days, a.Last90Days
from reporting a 
   join Repository b 
      on a.RECORD_ID = b.RECORD_ID
where a.POL_OGN_EFF_DT >= '2008-11-01'
group by a.POL_PRI_RSK_ST_CD, 
   a.MASTER_COMPANY_NBR, 
   case when a.char046 is NULL then 'ERR'
        when a.char046 > '010' then '11+'
        else a.char046 end,
   a.Last7Days, a.Last30Days, a.Last90Days

但实际上,你根本没有聚合函数,只是对 select 中的每个表达式都有一个 group by,所以你只需要一个 Distinct key word,你根本不需要 group by:

select Distinct a.POL_PRI_RSK_ST_CD, 
  a.MASTER_COMPANY_NBR,
  case when a.char046 is NULL then 'ERR'
       when a.char046 > '010' then '11+'
       else a.char046 end as Policy_Years,
  a.Last7Days, a.Last30Days, a.Last90Days
from reporting a 
   join Repository b 
      on a.RECORD_ID = b.RECORD_ID
where a.POL_OGN_EFF_DT >= '2008-11-01'
于 2010-02-02T15:19:53.257 回答
0
select 
     day, year,
case
   when a.month is NULL then 'ERR'
   when a.month > '011' then '12'
   else a.month end as Month,
 a.Last7Days
于 2010-02-02T15:00:17.430 回答
0

我认为您在案件结束后缺少“AS”。

于 2010-02-02T15:00:27.633 回答
0

修正逗号:

select 
     day, year,
     case
       when a.month is NULL then 'ERR'
       when a.month > '011' then '12'
       else a.month 
     end Month,
     a.Last7Days
from [table]
于 2010-02-02T15:01:45.243 回答
0

在 and周围Day加上方括号Year,如下所示:

select a.[Day], a.[Year], ...
于 2010-02-02T15:02:42.663 回答