在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

你可能感兴趣的:(程序,数据库,python,服务器)