September 7, 2016 at 12:25 pm
Morning!
An attribute comes back with five answers.
NULL
P=Permanent
T=Temporary
B=Both
8=See Job Description
Using the line below I receive a value of PermanenTemporary as the t at the end of Permanent is being replace with Temporary.
How can I stop this from happening and have them show their own individual values?
replace(replace(replace(replace(Orders.ptemp, 'P', 'Permanent'), 'T', 'Temporary'), 'B', 'Both'), '8', 'See Job Description') AS 'Perm or Temp'
Thank you!
September 7, 2016 at 12:33 pm
elzool (9/7/2016)
Morning!An attribute comes back with five answers.
NULL
P=Permanent
T=Temporary
B=Both
8=See Job Description
Using the line below I receive a value of PermanenTemporary as the t at the end of Permanent is being replace with Temporary.
How can I stop this from happening and have them show their own individual values?
replace(replace(replace(replace(Orders.ptemp, 'P', 'Permanent'), 'T', 'Temporary'), 'B', 'Both'), '8', 'See Job Description') AS 'Perm or Temp'
Thank you!
Would help if you showed the entire query not just a snippet. From what you posted, I wouldn't have a clue to how to actually help you.
Please remember, we can only see what you show us. Now, a guess would be that REPLACE is wrong and what you should look at is using CASE.
September 7, 2016 at 12:36 pm
Maybe something like this:
CASE Orders.ptemp
WHEN 'P' THEN 'Permanent'
WHEN 'T' THEN 'Temporary'
WHEN 'B' THEN 'Both'
WHEN '8' THEN 'See Job Description'
END AS 'Perm or Temp'
You could also use a look up table and join it to get the description. That would prevent to make changes to code if another option becomes available.
September 7, 2016 at 12:48 pm
Lynn, CASE nailed it, thank you!!
Luis, that is identical to what I just wrote up and works like a charm!
Thank you both!!
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply