SQL Server:将数据类型varchar转换为float时出错 [英] SQL Server: Error converting data type varchar to float

查看:2764
本文介绍了SQL Server:将数据类型varchar转换为float时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下SELECT语句来计算RADIANSCOS.

I have the following SELECT statement to calculate RADIANS and COS.

SELECT COS(RADIANS(latitude)) as Lat 
FROM tbl_geometry;

但是我遇到一个错误:

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

Error converting data type varchar to float.

我的尝试:

尝试#1 :

select Cos(convert(float, (Radians(convert(float, latitude))))) as Lat 
from tbl_geometry;

尝试#2 .

select Cos(Radians(convert(float, latitude))) as Lat 
from tbl_geometry;

两次尝试都会导致相同的错误.

Both attempts result in the same error.

注意:列Latitude的类型为varchar.

推荐答案

使用try_convert()查找无效数据:

select latitude
from tbl_geometry
where try_convert(float, latitude) is null;

try_convert()在SQL Server 2012+中可用.

try_convert() is available in SQL Server 2012+.

这篇关于SQL Server:将数据类型varchar转换为float时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆