extracting info from LDAP column?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Marjeta
    New Member
    • Sep 2008
    • 25

    extracting info from LDAP column?

    I have a table with one of the columns being ldap info. Example value would be:
    ou=FOO,ou=BAR,o =XYZ,dc=WORLD

    From this I would like to extract the first string, in this case FOO.

    My last attempt was:

    [CODE=mysql]SELECT 1+instr(T.ldap, "=") as startpos,
    instr(T.ldap,", ") as endpos,
    mid(T.ldap,star tpos,endpos-startpos)
    FROM myTable T where ldap like @likeStr;[/CODE]

    which gives me error message:
    ERROR 1054 (42S22): Unknown column 'startpos' in 'field list'


    1+instr(T.ldap, "=") evaluates to the correct value -- 4 for the example ldap field value on the top
    Same with instr(T.ldap,", ") -- 7 in the example

    And mid(T.ldap,4,7-4) would give me the correct value -- FOO in the example

    However, I can not rely on the numbers 4 and 7.

    Any suggestions?
    Last edited by mwasif; Mar 12 '09, 07:22 PM. Reason: Added CODE tags
  • Jibran
    New Member
    • Oct 2008
    • 30

    #2
    Use substring() as shown below:

    mysql> SELECT SUBSTRING('Quad ratically',5);
    -> 'ratically'

    Comment

    • mwasif
      Recognized Expert Contributor
      • Jul 2006
      • 802

      #3
      You can not use column aliases in functions, change your query as follows
      [CODE=mysql]SELECT
      mid(T.ldap,1+in str(T.ldap,"=") , (instr(T.ldap," ,")-1) + instr(T.ldap,"= "))
      FROM myTable T where ldap like @likeStr;[/code]

      Comment

      • Marjeta
        New Member
        • Sep 2008
        • 25

        #4
        Originally posted by mwasif
        You can not use column aliases in functions, change your query as follows
        [CODE=mysql]SELECT
        mid(T.ldap,1+in str(T.ldap,"=") , (instr(T.ldap," ,")-1) + instr(T.ldap,"= "))
        FROM myTable T where ldap like @likeStr;[/code]
        Thanks.
        That's what I ended up doing. I just don't like the idea of the same expression being calculated twice.

        Comment

        Working...