Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Expression (if 4th digit is 4 then "S" else if 6 then "U", e 1

Status
Not open for further replies.

kernal

Technical User
Feb 27, 2001
415
US
I have a field. Example:

1064
1066
1068

Fourth digit: If 4 then "S" else if 6 then "U" else if "8" then "F"

then take the second and third digits so my results would be:

S06
U06
F06

Help is appreciated.
 
Here are sample data, including an extra row to show what happens if there is a value that you didn't account for, above:
Code:
SQL> select * from kernal;

       VAL
----------
      1064
      1066
      1068
      1069
Here is code to do what you asked for:
Code:
select decode(substr(val,4,1),'4','S','6','U','8','F','x')
            ||substr(val,2,2) value
  from kernal;

VAL
---
S06
U06
F06
x06
Let us know if this takes care of business for you.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top