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

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 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

------解决方案--------------------
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