sql 数字转化 学习心得。

本文主要介绍了SQL中数字转换的一些常用方法,包括使用convert和cast函数进行numeric和decimal类型的转换,以及在实际操作中如何更新和插入数据。通过示例展示了如何处理表中的数据,如更新字段值、删除和插入数据等。
摘要由CSDN通过智能技术生成

1。convert(numeric(8,2),num)返回两个位数的小数

2.convert(decimal(15,2),12.2)返回两个位数的小数

3.cast(SUBSTRING(PrescriptionValue,2,5)as decimal)  类型转换

4.update PrescriptionVal set  PrescriptionValue='+' + CAST( convert(numeric(8,2),cast(SUBSTRING(PrescriptionValue,2,5)as float)) as nvarchar(7)) where PrescriptionTypeID =6

 

删除表中的数据,不删除结构。

truncate table TaobaoGM.dbo.PrescriptionVal

go

将另外一张表中的数据插入到目的表中。

insert into TaobaoGM.dbo.PrescriptionVal 

select PrescriptionTypeID,PrescriptionValue,Sorter,IsShow from NewGM.dbo.OP_Prescription

 

更新表中的某一些字段值。

update PrescriptionVal set PrescriptionValue = convert(decimal(12,2),PrescriptionValue)+1.50

where PrescriptionTypeID = 6 or PrescriptionTypeID = 7

 

update PrescriptionVal set IsShow = 0

where (convert(decimal(12,2),PrescriptionValue)<3.5 

or c

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值