请教一个数据库 SQL SERVER 的问题
已有一个数据表 CP 有两个字段 T1 TCOUNT 
表格式如下 
T1     TCOUNT    SUP 
 1       12
 2       13
 3       45
 ..      ..
 30      42
SUP 是新建的字段 如何赋值 使 SUP 字段的值 是
TCOUNT 值 /585 
哪位可以指教下 如何用SQL 语句实现 啊update  表名 set sup=tcount/585 where sup is null 
 为什么 运行后 SUP 值 都是 0 呢?TCOUNT 是NVARCHAR 类型   SUP 是FLOAT

解决方案 »

  1.   

    用下面的例子
    select CONVERT(NUMERIC(10,2),CONVERT(NUMERIC(10,2),23)/CONVERT(NUMERIC(10,2),100))
      

  2.   

    create table CP(T1 int, TCOUNT nvarchar(10), SUP float)
    insert CP select 1,       12, null
    union all select  2,       13, null
    union all select  3,       45, null
    union all select  30,      42, nullupdate CP set SUP=cast(TCOUNT as decimal(18, 0))/585
    where SUP is nullselect *from CP
    --result
    T1          TCOUNT     SUP                                                   
    ----------- ---------- ----------------------------------------------------- 
    1           12         2.0511999999999999E-2
    2           13         2.2221999999999999E-2
    3           45         7.6923000000000005E-2
    30          42         7.1793999999999997E-2(4 row(s) affected)
      

  3.   

    create table CP(T1 int, TCOUNT nvarchar(10), SUP float)
    insert CP select 1,       12, null
    union all select  2,       13, null
    union all select  3,       45, null
    union all select  30,      42, null
    30行是不是要一句一句写啊 ?那是不是太烦了点?
    呵呵,我刚开始学习数据库,希望大家多多指教。
      

  4.   

    update CP set SUP=cast(TCOUNT as decimal(18, 0))/585
    where SUP is null
      

  5.   

    update CP set SUP=cast(TCOUNT as decimal(18, 0))/585
    where SUP is null利用这条语句修改的时候,当TCOUNT 为10以上数值的时候还正常,当TCOUNT是个位数例如1的时候,运行结果就会出现 SUP=0.求教为什么呢