UPDATE with two conditions

0

I would like to make a UPDATE where I have two conditions; wanted to put the two together in one, if not one is the other.

FIRST:

UPDATE RLT005
SET CtrDatBaixa = '2018-12-15 00:00:00'
WHERE
CtrDatBaixa BETWEEN '2018-12-15 00:00:00' AND '2018-12-15 23:59:59'

SECOND:

UPDATE RLT005
SET CtrDatBaixa = '2018-12-31 00:00:00'
WHERE
CtrDatBaixa BETWEEN '2018-12-31 00:00:00' AND '2018-12-31 23:59:59'
    
asked by anonymous 17.12.2018 / 18:53

2 answers

2

So I understood "to put the two in one" , it would look something like this:

UPDATE RLT005
SET CtrDatBaixa = 
    CASE WHEN CtrDatBaixa BETWEEN '2018-12-15 00:00:00' AND '2018-12-15 23:59:59' THEN '2018-12-15 00:00:00' 
    CASE WHEN CtrDatBaixa BETWEEN '2018-12-31 00:00:00' AND '2018-12-31 23:59:59' THEN '2018-12-31 00:00:00'
    ELSE CtrDatBaixa END
    
17.12.2018 / 19:24
0

Explaining better to a friend of mine, gave me the following suggestion:

UPDATE RLT005 
SET CtrDatBaixa = CONCAT(FORMAT(CtrDatBaixa, 'yyyy-MM-dd'), ' 00:00:00')
WHERE DATEPART(DAY, CtrDatBaixa) in (15, DATEPART(DAY, EOMONTH(CtrDatBaixa)))
    
17.12.2018 / 20:18