如何将数据库里值前面的‘-’号去掉?得到一个正数就可以了。要求很简单,值不变,只需去掉前面的负号即可示例:  数据库原值:  -45.16        更改之后的值为:45.16
       数据库原值:  -31.27        更改之后的值为:31.27      等等。这个update的语句该怎么写?

解决方案 »

  1.   

    update tablename set filedname= abs(fieldname)
      

  2.   

    declare @table1 table

    id int,
    name nvarchar(50),
    表现分 decimal(10,1)
    )insert into @table1
    select 1,'王小二',-85 union all
    select 23,'章小品',90 union all
    select 33 ,'郭培育',75 union
    select 44 ,'exception',60
    select * from @table1
    update @table1
    set 表现分 =abs(表现分)select * from @table1
      

  3.   

    update t  set num=replace(num,'-','')
      

  4.   

    select abs(-45.16)
    select abs(-31.27)
      

  5.   

    看存值的字段是什么类型的了,
    varchar的话用replace,也可以转换成整型再ABS
    整型的话用ABS
    楼上都正确
      

  6.   

    打卡查询分析器,数学函数第一个 abs()
    接分
      

  7.   

    这样处理效率更高:
    update tablename set fieldname=-fieldname where fieldname<0再耍几个更不一样的:
    update tablename set fieldname=abs(fieldname) where fieldname<0
    update tablename set fieldname=sqrt(fieldname*fieldname)
    update tablename set fieldname=right(convert(varchar,fieldname),len(convert(varchar,fieldname)-1) where fieldname<0
    算法不同而已,效率也不一样.
      

  8.   

    abs,replace都可以达到,还有17楼的方法都能
      

  9.   

    ABS
    返回给定数字表达式的绝对值
      

  10.   

    update 表名
      set 列名= abs(列名)
    where
      列名<0