zoukankan      html  css  js  c++  java
  • 利用某一列的值改动之后来更新其自己

    --需求说明。在signBook2中有一列date_time,值是201210201221,我须要将其前面的2012,改成2014,所以写了以下这段存储过程

    --_id是表中的一列,是主键identity的

    declare @i int
    declare @datetime varchar(50)
    set @i=613
    while(@i<678)
    begin
    set @datetime =(select date_time from signBook2 where _id=@i)
    --以下这句,也是能够的
    --select @datetime = date_time from signBook2 where _id = @i
    print @datetime--此句输出datetime的值
    --substring(expression,start,length)
    print substring(@datetime,5,9)
    print str(@datetime)--刚開始,我使用这个函数,造成了错误,此处会将变量的值变成'**********'
    set @datetime = '2014'+ltrim(substring(@datetime,5,9))
    print @datetime
    update signBook2 set date_time=@datetime where _id=@i
    set @i=@i+1
    end

    --总结。经网上查证,str函数->str(nExpres[,nLength[,nDecimalPlaces]])
    --nExpression------str要计算的数值表达式.
    --nLength------------str返回的字符长度。该长度包含小数点所占的字符和小数点右边每一个数字所占的字符。
    --假设指定长度大于小数点左边数字位数,str()前导空格填充返回的字符串。
    --假设指定长度小于小数点左边的数字位数。str()返回一串星号。表示数值溢出。
    --nDecimalPlaces---由STR()返回字符串中的小数位数。

    若要指定小数位数,必须同一时候包括nLength。

    --假设指定的小数位数小于nExpress中的小数位数,则截断多余的数字。
    --返回值类型->字符型
    --当数字转换为字符串时。始终未Number的符号保留一个前导空格,假设Number为正,则返回字符串包括前导空格,并暗含加号。

    负数将包括减号(-),且没有前导空格。

  • 相关阅读:
    NYOJ 625 笨蛋的难题(二)
    NYOJ 102 次方求模
    ZJU Least Common Multiple
    ZJUOJ 1073 Round and Round We Go
    NYOJ 709 异形卵
    HDU 1279 验证角谷猜想
    BNUOJ 1015 信息战(一)——加密程序
    HDU 1202 The calculation of GPA
    "蓝桥杯“基础练习:字母图形
    "蓝桥杯“基础练习:数列特征
  • 原文地址:https://www.cnblogs.com/yutingliuyl/p/6903125.html
Copyright © 2011-2022 走看看