更新column1 case @ Date1和@ Date2之间的日期

时间:2016-12-17 06:03:03

标签: sql sql-server

我想从另一列的日期条件更新一列。

DECLARE @FIRSTDATE DATE ='2016-11-01';
DECLARE @LASTDATE DATE ='2016-11-30';

UPDATE A 
SET A.Status = CASE 
                  WHEN B.Date IS NULL THEN 0
                  ELSE 1 
               END,
    A.DESCRIPTION = CASE  
                       WHEN B.Date IS NULL 
                          THEN 'UNPAID'
                       WHEN B.Date BETWEEN @FIRSTDATE AND @LASTDATE  
                          THEN 'CARRY FORWORD'
                       ELSE 
                          'PAID'   
                     END
FROM TABLE1 AS A
JOIN TABLE2 AS B ON A.ID = B.ID;

0 个答案:

没有答案