字段:   a            b          c 
值       86         000000      a字段的值是会变的,b字段是指c字段的长度也就是六位,怎么写SQL语句使c等于000086呢?

解决方案 »

  1.   

    update tb
    set c=right(b+ltrim(a),len(b))
      

  2.   

    update tb set c=right(b+ltrim(a),6)
      

  3.   


    update tb 
    set c=right(b+ltrim(a),len(b)) 
      

  4.   

    if object_id('[tb]') is not null drop table [tb]
    go
    create table [tb]([a] int,[b] varchar(6),[c] varchar(10))
    insert [tb]
    select 86,'000000',null
     
    update tb
    set c=right(b+ltrim(a),len(b))
    select * from [tb]
    /**
    a           b      c          
    ----------- ------ ---------- 
    86          000000 000086(所影响的行数为 1 行)
    **/
      

  5.   

    update tb set c=substring(a+b,len(a),len(a+b))
      

  6.   

    呃,刚看到a是数值型的--也可以这样update tb set c=substring(b+ltrim(a),len(ltrim(a)),len(ltrim(a)+b))--不过没有right简单就是了