环境:sqlserver2000 +win2003
问题:想让成绩表的绩点字段设置默认值为(60分以下为0分,60及以上绩点为:(成绩-50)/10),当成绩变动后绩点也随之变动。请前辈指导!成绩表 
学号     成绩  绩点
20050001    80    (3)
20050002     95  (4.5)
20050003   40   (0)
20050004   60   (0)绩点要求:60分以下为0分,60及以上绩点为:(成绩-50)/10

解决方案 »

  1.   


    select *,case when (convert(float,成绩)-50)/10<0 then 0 else (convert(float,成绩)-50)/10 end as 绩点 from 成绩表
    不知道2000能不能用,试下吧
      

  2.   


    支持利用视图CREATE TABLE test2(
    XH VARCHAR(20),
    CJ NUMERIC
    )INSERT INTO test2
    SELECT '1','50' UNION ALL
    SELECT '2','60' UNION ALL
    SELECT '3','13' GO
    CREATE VIEW vt1 AS SELECT XH "学号",CJ"成绩",(CJ-50)/10 "积点"  FROM test2
    GO
    SELECT * FROM vt1DROP  TABLE test2
    GO
    DROP  VIEW vt1
    GO
      

  3.   

    视图是一种方法,计算列也可以做到。
    create table 成绩表
    (
    学号 varchar(20),
    成绩 decimal(10,1),
    绩点 as case when isnull(成绩,0)<60 then 0 else ((成绩-50)/10) end
    )
    insert into 成绩表 (学号,成绩) values ('201201',50)
    insert into 成绩表 (学号,成绩) values ('201202',80)
    select * from 成绩表
      

  4.   

    create table txxx(xh varchar(10),score decimal(3,1),dot as (score-50)/3 )
      

  5.   

    select 学号,成绩,[绩点]=case when 成绩<60 then 0 else (成绩-50)/10 end from 表 with(nolock)四楼的应该可以