当前位置:首页 > 技术心得 > 正文内容

SQL去掉小数点有效数字后的所有0

xjtudll4年前 (2022-01-08)技术心得3840
  • 第一种方法

select cast(2.5000000000000   as  real)

select cast(2   as  real)

select cast(2.00000   as  real)

  • 第二种方法

CREATE function [dbo].[ClearZero](@inValue varchar(50))

returns varchar(50)

as

begin

declare @returnValue varchar(20)

if(@inValue='')

   set @returnValue='' --空的时候为空

else if (charindex('.',@inValue) ='0')

   set @returnValue=@inValue --针对不含小数点的

else if ( substring(reverse(@inValue),patindex('%[^0]%',reverse(@inValue)),1)='.')

          set @returnValue =left(@inValue,len(@inValue)-patindex('%[^0]%',reverse(@inValue))) --针对小数点后全是0的

      else

          set @returnValue =left(@inValue,len(@inValue)- patindex('%[^0]%.%',reverse(@inValue))+1) --其他任何情形

return @returnValue

end

扫描二维码推送至手机访问。

版权声明:本文由鸟的天空发布,如需转载请注明出处。

本文链接:http://www.xjtudll.cn/Exp/628/

分享给朋友:

“SQL去掉小数点有效数字后的所有0” 的相关文章

Warning: xx pins must meet Altera requirements for 3.3-, 3.0-, and 2.5-V interfaces. For more information, refer to AN 447: Interfacing Cyclone IV E Devices with 3.3/3.0/2.5-V LVTTL/LVCMOS I/O Systems

Warning: xx pins must meet Altera requirements for 3.3-, 3.0-, and 2.5-V interfaces. For more information, refer to AN 447: Interfacing Cyclone IV E Devices with 3.3/3.0/2.5-V LVTTL/LVCMOS I/O Systems

问题描述: Cyclone IV EP4CE6E22C8N Quartus II编译 每次编译完,都有个warning: Warning: xx pins must meet Altera requirements for 3.3-, 3.0-, and 2.5-V interfaces. For...

魅族Flyme7不显示logcat

魅族Flyme7不显示logcat

设置 -> 辅助功能 -> 开发者选项 -> Flyme扩展功能 -> 性能优化 -> 高级日志输出 -> 全部允许 没有开发者选项的先去系统设置里将开发者选项给点出来...

android禁止屏幕自动锁屏(或背光自动灭)

  Android开发过程中,一些程序在运行时,不希望手机自动锁屏,即保持系统的背景灯常亮,以防止程序执行时出现异常,实现起来很简单,只需要在创建Activity时,在onCreate()方法中,加入如下语句即可。   getWindow().addFlags(WindowMan...

VSPD + Keil 实现串口的仿真调试

VSPD + Keil 实现串口的仿真调试

VSPD顾名思义就是在本本上虚拟串口,实际上这个软件做的就是虚拟出一对已经互联的串口。 上面就是虚拟出来了com3和com4,而且已经交叉(默认)连接了,这样相当于本本的com3、com4在外面已经连好了,下面要做的就是在内部分别赋予com3和com4所属终端了。 com4—&mda...

c# winform 查看网络图片

引用网址:https://blog.csdn.net/weixin_30462049/article/details/99170485 /// <summary>         /// ...

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。