Skip to Content
author's profile photo Former Member
Former Member

Index Function

Hi,

I need to input certain values based on certain logic.

It is like if the 8'th character is empty or contains numeric then PART field contains value BCI and if 8'th character contains alphabet, then PART = 'DFI'

Below is the example:

If ID = 1234567 then PART = 'BCI'

ID = 12345678 then PART = ''BCI'

ID = 1234567AP01 then PART = 'DFI'

How do I write it using INDEX?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Jul 14, 2011 at 07:41 AM

    Hi Naga,

    Do you have access to the online technical manuals that are supplied with Data Services ? If not, I suggest you installl them because you will get much faster answers to these types of questions (usage of the built-in functions) from the manuals (particularly the reference guide) than you will from forums (and more accurate in some cases). The manuals are very well written and there are usually lots of examples.

    Having said that, to guide you in the right direction the 'substr' function is probably going to be the one to look at since you know exactly which character you need to identify in the string (i.e. the 8 th). The 'index' function is more suited to cases where you are looking for a sequence of characters in a string and want to know at which position the first occurrence of the character sequence begins.

    So basically, use 'substr' to get the 8th character inside a 'decode' function to compare this value to your three cases and determine the output.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Also, you can handle all three of your conditions in one decode statement because decode works like nested ifthenelse functions, eg. in this example from the manual:

      decode ((EMPNO = 1), '111',

      (EMPNO = 2), '222',

      (EMPNO = 3), '333',

      (EMPNO = 4), '444',

      'NO_ID')

      If EMPNO=1 it returns '111', else it checks the next condition,

      If EMPNO=2 it returns '222', else it checks the next condition,

      If EMPNO=3 it returns '333', else it checks the next condition,

      If EMPNO=4 it returns '444', else it returns the default expression 'NO_ID'

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.