表1
id name type holiday socre
1   a    1     360    null
2   b    2     100    null
3   c    3     120    null表type 
id name minday maxday
1    x    6     10 
2    y    8     16
3    z    10    20说明:表1中的type和表type是外键关系。我想通过存储过程更新表1的socre字段的所有值。条件是根据每个人的type确定出
每个人的最小天数和最大天数,然后根据holiday除以365得到个数和最小天数相加赋给socre谢过了....

解决方案 »

  1.   

    holiday除以365每个月算一次,加最小天数,知道最大天数maxday
      

  2.   

    if object_id('[t1]') is not null drop table [t1]
    go
    create table [t1]([id] int,[name] varchar(1),[type] int,[holiday] int,[score] int)
    insert [t1]
    select 1,'a',1,360,null union all
    select 2,'b',2,100,null union all
    select 3,'c',3,120,null
    go
    if object_id('[type]') is not null drop table [type]
    go
    create table [type]([id] int,[name] varchar(1),[minday] int,[maxday] int)
    insert [type]
    select 1,'x',6,10 union all
    select 2,'y',8,16 union all
    select 3,'z',10,20
    gocreate proc sp_test
    as
    update a
    set score=a.holiday/360+b.minday
    from t1 a,[type] b
    where a.[type]=b.id
    and a.holiday/360+b.minday<=b.maxday
    go--用定时作业设定每月执行一次 exec sp_testselect * from t1
      

  3.   

    但是有一个问题,如果你的holiday和minday一直不改变,这个score值怎么update也是相同的
      

  4.   

    holiday是每天加1的,有语句控制的。minday是最小值,是固定的,maxday是最大值也是固定,其实这个是算年假的,就是某个人刚入职,然后他起始是minday,每年的1月1日判断,是否满365天,满的话则在minday+1天,type是人的级别。不同的人不同的年假区间
      

  5.   

    create proc sp_test
    as
    update a
    set score=a.holiday/365+b.minday
    from t1 a,[type] b
    where a.[type]=b.id
    and a.holiday/365+b.minday<=b.maxday
    go这个OK?