This discussion is archived
2 Replies Latest reply: Dec 5, 2012 2:37 PM by 976439 RSS

Need help with query

976439 Newbie
Currently Being Moderated
Hi, looking for some help in writing a query. i currently have 2 columns, 1 shows a fault number and another a telephone, what i would like to do is select both these fields and if the fault number has the character 'NA' in any rows than I would like this to be replaced by the value in the telephone number.

As i understand there are 3 ways, replace, translate and regexp but not sure going foward which would be the best way and also I currently have selected data from 2 tables and have a union all to put the data together, but not sure how i can replace the NA value.

To summarise this is what i currently have

SELECT
FROM
INNER JOIN
UNION ALL
SELECT
FROM
INNER JOIN

If somebody could please help, would really appreciate it.
  • 1. Re: Need help with query
    MLBrown Journeyer
    Currently Being Moderated
    You should post your question in the SQL PL/SQL forum instead of this one: {forum:id=75}

    BUT, you probably need to include a better problem description because I'm not sure what you are trying to do. You should give an example of your data and a sample of what your output should look like. If possible you should include a table creation script and insert statements with the data you want us to look at. It makes solving the problem much easier.

    Based on what I read, it looks like you are trying to print the fault number unless it is NA then you want to print the telephone number. If that is the case, you could do something like:
    --
    -- If fault is NA select phone_number else fault number
    --
    select decode(fault, 'NA', telephone, fault) phone_number
      from table_name;
    If that isn't it, then you should close this and post the question in the other forum.
  • 2. Re: Need help with query
    976439 Newbie
    Currently Being Moderated
    MLBrown, apologies for posting in the wrong area. That function is exactly what I was looking for, thank you very much. Will test this out and have a play.

    Thanks once again!! : )

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points