I have a field of nvarchar(6). It contains date information. The source data file is for a COBOL system. Any date from 1/1/2000 to 12/31/2009 comes in with a leading colon. For instance, May 5, 2000 translates to ":00505" (formatted YYMMDD). It should be changed to "000505" by the derived column. Any date from 1/1/2010 until 12/31/2019 comes in with a leading semicolon. For instance, April 15, 2011 translates to ";10415" (formatted YYMMDD). It should be changed to "110415" by the derived column. Any date from 1/1/2020 to 12/31/2029 is going to come in with a leading "<." For instance, June 9, 2020 translates to "<00609" (formatted YYMMDD). It should be changed to "200609" by the derived column. Simple procedural code should read something like this:
IF DF_DATE = ":%" THEN
DF_DATE = "0%"
ELSE IF DF_DATE = ";%" THEN
DF_DATE = "1%"
ELSE IF DF_DATE = "<%" THEN
DF_DATE = "2%"
How do write this in a derived column? I can change it easily enough if I only want to change the leading zero by using the following:
REPLACE(DF_DATE, ":", "0")
But what about the other two errant symbols? I thought I would ask rather than skim the web for four hours. Thank you all...far in advance.
R. J. Head