我要更新这个EmployeesAttendance 表AbsenteeismHours 字段值为5,条件是
PublicRest表里面Sunday字段为1时,EmployeesAttendance表DateMonths星期六星期天时就不更新.其它的更新
如果PublicRest没有数据时就全更新.
我写成下面这样PublicRest表没有数据.就全不更新了,不知为什么UPDATE EmployeesAttendance SET AbsenteeismHours = 5FROM EmployeesAttendance,PublicRest
 WHERE NOT EXISTS(SELECT 1 FROM PublicRest WHERE EmployeesAttendance.PostID=PublicRest.PostID AND 
DATEPART(dw,DateMonths) IN (1,7)and PublicRest.Sunday = 1)

解决方案 »

  1.   


    UPDATE EmployeesAttendance 
    SET AbsenteeismHours = 5
    FROM PublicRest
    where EmployeesAttendance.PostID=PublicRest.PostID
    and DATEPART(weekday,DateMonths) not IN (1,7)
    and PublicRest.Sunday = 1
      

  2.   

    这样和我写差不多,也是PublicRest表没有数据就没有更新....
      

  3.   

    PublicRest没有数据 PublicRest.Sunday = 1就不成立 怎么会更新呢
      

  4.   


    UPDATE EmployeesAttendance SET AbsenteeismHours = 5
    FROM EmployeesAttendance
     WHERE NOT EXISTS(SELECT 1 FROM PublicRest WHERE EmployeesAttendance.PostID=PublicRest.PostID AND 
    DATEPART(dw,DateMonths) IN (1,7)and PublicRest.Sunday = 1)
    请去掉PublicRest这张表
    不然无法更新的,去掉后能正常的
      

  5.   

    update #a
    set a='a'
    from #a,#b
    你这样写的话
    如果b表为空集的话,是无法更新a表的
      

  6.   

    我是要当PublicRest表里面的数据这里面有数据Sunday为1是不更新里面的列.其它的更新,也就是当这个表里里面不存在数据时,也需要更新.只是条件没有为1而已呀
      

  7.   

    我表示以我的知识,一句话搞不定,分多句吧。先判断PublicRest里有无数据
      

  8.   

    UPDATE EmployeesAttendance SET AbsenteeismHours = 5FROM EmployeesAttendance,PublicRest
     WHERE NOT EXISTS(SELECT 1 * FROM PublicRest WHERE EmployeesAttendance.PostID=PublicRest.PostID AND 
    DATEPART(dw,DateMonths) IN (1,7)and PublicRest.Sunday = 1)
    你直接select 1,那么跟没查有啥区别,加个*或者其他字段就应该OK了。试下。
      

  9.   

    --这样试试
    UPDATE EmployeesAttendance SET AbsenteeismHours = 5
    FROM EmployeesAttendance
    --如果PublicRest没有数据时就全更新
    where not exists (select 1 from PublicRest)
    --PublicRest表里面Sunday字段为1时,EmployeesAttendance表DateMonths星期六星期天时就不更新
    or exists (SELECT 1 FROM PublicRest WHERE EmployeesAttendance.PostID=PublicRest.PostID AND 
    DATEPART(dw,DateMonths) not IN (1,7)and PublicRest.Sunday = 1)