I'm attempting to fix some of the dates I have in my SQL table. For context, I joined the two tables, Trade Details and Trade Details 2 together. One of the columns in Trade Details 2 is START_DATE with dates ranging back to the early 2000's in the format 2010-05-08. I'm looking to make every START_DATE before 2018-06-22 into 2018-06-22. Currently, my code is below:
SELECT "Trade Details 2".Portfolio,
"Trade Details 2".CONTRACT_ID,
DATE("Trade Details 2".START_DATE) as START_DATE,
DATE(substr("Trade Details 2".MATURITY_DATE, 0, 5) || '-' ||
substr("Trade Details 2".MATURITY_DATE, 5,2) || '-' ||
substr("Trade Details 2".MATURITY_DATE, 7, 9)) as MATURITY_DATE,
"Trade Details 2".NOTIONAL1,
"Trade Details 2".CONTRACT_NPV,
"Trade Details".TERM
FROM "Trade Details 2"
JOIN "Trade Details"
WHERE "Trade Details 2".CONTRACT_ID="Trade Details".FCC_ID and
("Trade Details 2".NOTIONAL1 > "0.0") and
("Trade Details 2".MATURITY_DATE > DATE(substr('20180602', 0, 5) || '-' ||
substr('20180602', 5,2) || '-' || substr('20180602', 7, 9)))
ORDER BY CONTRACT_ID asc
I believe that what I need is a CASE WHEN expression, where I say something like:
CASE WHEN "Trade Details 2".START_DATE<2018-06-22 THEN =2018-06-22
However, when I tried this, I got an error, and I'm guessing that some part of this line of code is wrong. Since this is a date, I don't know if a greater than/less than symbol will suffice, and I'm not sure where to put this expression, or even if this expression is totally correct.
This is the gist of my question. This is different from other questions on here I believe because it's dealing with dates instead of simple numbers.
TLDR; Trying to turn dates prior to 2018-06-22 into 2018-06-22, but not sure how to do this.
MAX(..)function, will that not work?Max("2018-06-22", "Trade Details 2".START_DATE"somewhere? Which line would I put this code on?CASEstatement, just part of the columns listed in theSELECT. Also, just noticed this, having tables with spaces is frowned upon. Not least because of the need to put delimiters around them every time...