sql server - How to modify my T-SQL UPDATE query by adding a CONDITIONAL clause? -
i'm using sql server 2014 , have update query runs on 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 update rateamount column , update query follows:
use mydatabase update resstaydate set rateamount = case resid when 256 155.00 else rateamount end
my problem if run query "as is", update rows 155.00. need update rows staydate
in december 2015.
output should 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 modify query updates part of resstaydate
table?
if want affect records in december, use datepart function:
use mydatabase update resstaydate set rateamount = case when resid = 256 , datepart(month,staydate) = 12 155.00 else rateamount end
Comments
Post a Comment