I have a probable easy question for someone. I need to compare two existing date values in SQL, fields A, and B. After I compare them, I need to add a condition that says, if field A is 30 days greater than field B, you should change the status in field C to some value. This should be executed every day.
I have an issue with comparing and setting condition. Trying to find the solution on overflow but didn't get the info that I need. All fields are in the same table.
I was trying something like basic update but then I've got thing in my mind that I should probable use function.
Maybe if you can provide me code for this case, it will be great!
CodePudding user response:
Solution:-
update table set C = <value> where DATEDIFF(d,B,A) > 30
CodePudding user response:
By this, I've managed to come to my solution. In an addition, I had to use the try_Convert function to get the exact date type for calculation!
Thank you!
