3

I have a case statement where I am trying to change two values from a field.

CASE
WHEN prod_map.Product_ID1 = 'CR'  
THEN REPLACE(REPLACE(cl.trade_day_count, 'ACT','ACTUAL'),cl.trade_day_count, 
'ACT+1', 'ACTUAL')
END,

so, when cl.trade_day_count contains the value 'ACT' or 'ACT+1' then change to 'ACTUAL'

2
  • The result of the 1st replace is the value you want to use as the 1st parameter on the 2nd replace function; thus you don't need cl.trade_date_count again. Replace takes 3 parameters if I recall, your outer most is showing 4. Commented Sep 21, 2017 at 17:29
  • If we can assume ~ isn't in cl.trade_day_count and never will be... rextester.com/XYVO11480 Replace(REPLACE(REPLACE('~'+cl.trade_day_count+'~', '~ACT+1~','ACTUAL'),'~ACT~', 'ACTUAL'),'~','') Commented Sep 21, 2017 at 17:59

1 Answer 1

2

Working answer from Alex K. comment:

REPLACE(REPLACE(cl.trade_day_count, 'ACT','ACTUAL'),'ACTUAL+1', 'ACTUAL')
Sign up to request clarification or add additional context in comments.

9 Comments

This would replace ACT+1 -> ACTUAL+1 but I think he wants ACTUAL on its own & has an overlap problem
REPLACE(REPLACE(cl.trade_day_count, 'ACT','ACTUAL'),'ACT+1', 'ACTUAL') seems to work fine for ACT or ACT+1 values.
@fercstar Regarding edit: How do you know they don't want all other values to be null? the else wasn't in the original question. maybe when it's CR they only want ACT and ACT+1 values but displayed with Actual?
the inner ACT to ACTUAL makes ACT+1 into ACTUAL+1 which does not match the next ACT+1 replace, REPLACE(REPLACE(cl.trade_day_count, 'ACT','ACTUAL'),'ACTUAL+1', 'ACTUAL') would work I think.
@alexK you're right. I even wrote a demo and misread the results!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.