当前位置: 代码迷 >> Sql Server >> varchar 转 int,该如何解决
  详细解决方案

varchar 转 int,该如何解决

热度:56   发布时间:2016-04-27 13:48:08.0
varchar 转 int
我的目的是:先把字段HFNR_KHMYD中的汉字转换为1,2...等,然后分组求和hfnr_khmyd,代码如下:

select hfnr_sjwj,sum(convert(int as hfnr_khmyd), )
case when hfnr_khmyd='满意' then 3
when hfnr_khmyd='基本满意' then 2
when hfnr_khmyd='一般' then 1
when hfnr_khmyd='不满意' then 0 end 
else -1 end as 客户满意度
from cc_hfnr 
group by hfnr_sjwj


错误:消息 156,级别 15,状态 1,第 1 行
关键字 'convert' 附近有语法错误。

请教一下。。。

------解决方案--------------------
SQL code
select hfnr_sjwj,sum(case when hfnr_khmyd='满意' then 3when hfnr_khmyd='基本满意' then 2when hfnr_khmyd='一般' then 1when hfnr_khmyd='不满意' then 0 end else -1 end)as 客户满意度from cc_hfnr group by hfnr_sjwj
------解决方案--------------------
SQL code
select hfnr_sjwj,sum(case   when hfnr_khmyd='满意' then 3  when hfnr_khmyd='基本满意' then 2  when hfnr_khmyd='一般' then 1  when hfnr_khmyd='不满意' then 0   else -1 end) as 客户满意度from cc_hfnr group by hfnr_sjwj
  相关解决方案