SQL server2008存储过程中char(20) 怎么转成intset @data1 = cast(ltrim(rtrim(@data)) as int)
这个对不对?

解决方案 »

  1.   


    declare @t table (col char(20))
    insert into @t
    select '123' union all
    select '456' union all
    select '789'select col=col+0+123 from @t
    /*
    col
    -----------
    246
    579
    912
    */不去掉空格,也可以直接隐式转换。
      

  2.   

    首先3楼不对,55 ascii->  53
    我的数据是可以转换的,可能使后面空格的问题,cast不了,trim不起作用
      

  3.   

    這樣
    declare @t table (col char(20))
    insert into @t
    select '123' union all
    select '456' union all
    select '789'select col=col*1 from @t
    /*
    123
    456
    789
    */
      

  4.   


    用 rtrim--用這樣去掉結尾空格
      

  5.   


    直接轉換就行了不需要用什麼 去空格的轉為int時,空格會忽略的,除非空格在中間
      

  6.   

    select @Data0 = SUBSTRING('0123456789ABCDEF', @hour/16+1,1)+SUBSTRING('0123456789ABCDEF', @hour%16+1,1);接下去把这个@Data0 转成数字 是char(20)的
      

  7.   

    说明里面存的数据有问题,例如存在一些字母或是符合,或是超出int上限的数字。