REPLACE or alternative?

  • 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!

  • 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.

  • 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.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • 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