“将数据类型varchar转换为float时出错”:如何解决我的SQL查询中的此错误?

问题描述

我正在使用SQL Server 2014,并且具有以下T-SQL查询:

USE MyDatabase

;with cte1 as (    
    SELECT ID,Name,Age
    from [Table1]    
    Where ([Age] is NOT NULL OR [Age] >= 18)
),cte2 as 
(
    Select *,(case when [Age] between 18 and 24 then '18 - 24'
         when [Age] between 25 and 35 then '25 - 35'
         when [Age] between 36 and 45 then '36 - 45'
         when [Age] between 46 and 55 then '18 - 24'
         when [Age] between 56 and 65 then '18 - 24'
         when [Age] > 65 then 'Above 65'
         ELSE [Age]
         END) as [Age Group]    
    from [cte1]    
)    
SELECT *
from [cte2]

运行上面的代码时,出现以下错误:

将数据类型varchar转换为float时出错。

我知道该错误与我的[年龄] case expression有关,因为当我从查询中删除该case expression时,它运行正常。

注意:我表中的[年龄]列的类型为float,并包含NULL。

我尝试了此处提供的答案,但仍收到相同的错误消息:Error converting data type varchar to float

如何解决此错误?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)