在SQL语句里面如何将字符型转换成数字型
Posted xiexuzhao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在SQL语句里面如何将字符型转换成数字型相关的知识,希望对你有一定的参考价值。
在SQL语句里面如何将字符型转换成数字型
sql字符串转数字
用cast(金额 as decimal(10,4))或者 convert(decimal(10,4),金额)
SELECT 2023, sum( convert(decimal(10,4),[paymoney])) FROM [IMS_PUB_1].[dbo].[A]-- where SalaryMonth like '2015.%'
union all
SELECT 2015, sum( convert(decimal(10,4),[paymoney])) FROM [IMS_PUB_1].[dbo].[A] where SalaryMonth like '2015.%'
union all
SELECT 2016, sum( convert(decimal(10,4),[paymoney])) FROM [IMS_PUB_1].[dbo].[A] where SalaryMonth like '2016.%'
union all
SELECT 2017, sum( convert(decimal(10,4),[paymoney])) FROM [IMS_PUB_1].[dbo].[A] where SalaryMonth like '2017.%'
union all
SELECT 2018, sum( convert(decimal(10,4),[paymoney])) FROM [IMS_PUB_1].[dbo].[A] where SalaryMonth like '2018.%'
union all
SELECT 2019, sum( convert(decimal(10,4),[paymoney])) FROM [IMS_PUB_1].[dbo].[A] where SalaryMonth like '2019.%'
union all
SELECT 2020, sum( convert(decimal(10,4),[paymoney])) FROM [IMS_PUB_1].[dbo].[A] where SalaryMonth like '2020.%'
union all
SELECT 2021, sum( convert(decimal(10,4),[paymoney])) FROM [IMS_PUB_1].[dbo].[A] where SalaryMonth like '2021.%'
union all
SELECT 2022, sum( convert(decimal(10,4),[paymoney])) FROM [IMS_PUB_1].[dbo].[A] where SalaryMonth like '2022.%'
union all
SELECT SalaryMonth, convert(decimal(10,4),[paymoney]) FROM [IMS_PUB_1].[dbo].[A] where SalaryMonth like '2022.%'
(无列名) (无列名)
2023 887096.4100
2015 73909.5800
2016 86034.6400
2017 106196.8500
2018 111773.7400
2019 126841.2600
2020 108108.4000
2021 151869.9500
2022 122361.9900
2022.01 12426.3800
2022.02 12426.3700
2022.03 12426.3800
2022.04 12426.3700
2022.05 5794.2000
2022.06 9263.3100
2022.07 11555.1100
2022.08 10029.8400
2022.09 12004.6800
2022.1 12004.6700
2022.11 12004.6800
在SQL语句里面如何将字符型转换成数字型?
参考技术A 将字段修改成其它类型,需要修改表的结构,使用modistru命令进入表设计器,将birthday的类型改成字符型。 参考技术B 先检查金额列的数据是否都符合小数规范
用
cast(金额
as
decimal(10,4))>500
或者
convert(decimal(10,4),金额)>500
试试
decimal的长度和小数位数根据自己需要设定
以上是关于在SQL语句里面如何将字符型转换成数字型的主要内容,如果未能解决你的问题,请参考以下文章
怎么把“文件路径”这个字符串转换成数字型?转换完成后还是文件路径吗?