I'm using SQL Server 2014 and I have an UPDATE query that runs on a table called "ResStayDate" (extract shown below):
ID StayDate RateAmount
-----------------------------------
256 2015-11-28 248.00
256 2015-11-29 248.00
256 2015-11-30 248.00
256 2015-12-01 0.00
256 2015-12-02 0.00
256 2015-12-03 0.00
I need to update the RateAmount column and my UPDATE query is as follows:
USE MyDatabase
UPDATE ResStayDate
SET RateAmount = CASE ResID
WHEN 256 THEN 155.00
ELSE RateAmount
END
My problem is that if I run this query "as is", it will update ALL the rows with 155.00. I need to update only those rows where the StayDate is in December 2015.
Output should be like this:
ID StayDate RateAmount
---------------------------------
256 2015-11-28 248.00
256 2015-11-29 248.00
256 2015-11-30 248.00
256 2015-12-01 155.00
256 2015-12-02 155.00
256 2015-12-03 155.00
How do I modify my query so that it updates only that part of the ResStayDate table?