String query

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bernadette Houghton

    #1

    String query

    I'm trying to compare two fields in a table. If the whole of the first field
    is found somewhere within the second field, I need to output the second
    field into a third field..

    e.g.

    Field1 = abcd

    Field2 = xyzabcdefg

    Since Field1 is found within Field2, Field3 =xyzabcdefg

    I 'm able to do this if the wholecontents of Field1 exactly matches the
    whole contents of Field2, viz - Field3: IIF([Field1] = [Field2],[Field2],"")

    However, I can't get this expression to recognise when Field1 matches only
    part of Field2.

    Regards

    Bernadette



  • Fredg

    #2
    Re: String query

    [Field3] =IIf(Instr([Field2],[Field1)>0,[Field2],"")

    --
    Fred

    Please reply only to this newsgroup.
    I do not reply to personal e-mail.


    "Bernadette Houghton" <bhoughton@ozem ail.com.au> wrote in message
    news:eV5db.483$ lk1.13845@nnrp1 .ozemail.com.au ...[color=blue]
    > I'm trying to compare two fields in a table. If the whole of the first[/color]
    field[color=blue]
    > is found somewhere within the second field, I need to output the second
    > field into a third field..
    >
    > e.g.
    >
    > Field1 = abcd
    >
    > Field2 = xyzabcdefg
    >
    > Since Field1 is found within Field2, Field3 =xyzabcdefg
    >
    > I 'm able to do this if the wholecontents of Field1 exactly matches the
    > whole contents of Field2, viz - Field3: IIF([Field1] =[/color]
    [Field2],[Field2],"")[color=blue]
    >
    > However, I can't get this expression to recognise when Field1 matches only
    > part of Field2.
    >
    > Regards
    >
    > Bernadette
    >
    >
    >[/color]


    Comment

    • Matthew Reeves

      #3
      Re: String query

      "Bernadette Houghton" <bhoughton@ozem ail.com.au> wrote in message
      news:eV5db.483$ lk1.13845@nnrp1 .ozemail.com.au ...[color=blue]
      > I'm trying to compare two fields in a table. If the whole of the first[/color]
      field[color=blue]
      > is found somewhere within the second field, I need to output the second
      > field into a third field..
      >
      > e.g.
      >
      > Field1 = abcd
      >
      > Field2 = xyzabcdefg
      >
      > Since Field1 is found within Field2, Field3 =xyzabcdefg
      >
      > I 'm able to do this if the wholecontents of Field1 exactly matches the
      > whole contents of Field2, viz - Field3: IIF([Field1] =[/color]
      [Field2],[Field2],"")[color=blue]
      >
      > However, I can't get this expression to recognise when Field1 matches only
      > part of Field2.
      >
      > Regards
      >
      > Bernadette
      >[/color]

      Try the following query:

      UPDATE Table1 SET Field3 = Field2 WHERE Field2 Like '*' & Field1 & '*';


      Comment

      Working...