Using LIKE with IF....

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

    Using LIKE with IF....

    Hi,

    I have a recordset which pulls out specific customer names.
    One of our customers have many branches, i.e:
    Customer A Site 1
    Customer A Site 2
    Customer A Site 3
    etc.....

    I have the following IF statement, and want to catch all of the Customer A names...

    If RS("CustomerNam e") like Customer A * then........

    I just want to catch all customer names starting with 'Customer A'.

    I'm sure this statement will work, i'm just missing a quote or something ??

    Appreciate your help

    David
  • Aaron [SQL Server MVP]

    #2
    Re: Using LIKE with IF....

    Why don't you do this IN THE QUERY instead of while processing the results?

    You didn't mention what database you're using, but in SQL Server,

    SELECT
    Customer, site
    FROM wherever
    WHERE Customer LIKE 'Customer A%'

    This reduces the amount of network chatter and lets the engine use an index
    instead of returning all the data (often a more expensive table scan).

    However, if you insist that you want to do this in ASP, and just throw away
    the rest of the rows, then you can't use LIKE. LIKE is a SQL operator, not
    present in VBScript.

    strLike = "Customer A"
    strLen = Len(strLike)
    do while not rs.eof
    strDB = rs("CustomerNam e")
    if left(lcase(strD B), strLen) = lcase(strLike) then
    ........
    end
    rs.movenext
    loop

    However, I might suggest that your design is flawed, if all 'Customer A%'
    are the same customer, then perhaps you should be using a master table and
    inserting the ID of the customer instead...

    --
    Please contact this domain's administrator as their DNS Made Easy services have expired.

    (Reverse address to reply.)




    "David" <david@scene-double.co.uk> wrote in message
    news:c178e3e8.0 411030745.104cc 68c@posting.goo gle.com...[color=blue]
    > Hi,
    >
    > I have a recordset which pulls out specific customer names.
    > One of our customers have many branches, i.e:
    > Customer A Site 1
    > Customer A Site 2
    > Customer A Site 3
    > etc.....
    >
    > I have the following IF statement, and want to catch all of the Customer A[/color]
    names...[color=blue]
    >
    > If RS("CustomerNam e") like Customer A * then........
    >
    > I just want to catch all customer names starting with 'Customer A'.
    >
    > I'm sure this statement will work, i'm just missing a quote or something[/color]
    ??[color=blue]
    >
    > Appreciate your help
    >
    > David[/color]


    Comment

    • Curt_C [MVP]

      #3
      Re: Using LIKE with IF....

      If Aaron's suggestion doesn't work look at InStr()

      --
      Curt Christianson
      Owner/Lead Developer, DF-Software
      Site: http://www.Darkfalz.com
      Blog: http://blog.Darkfalz.com


      "David" <david@scene-double.co.uk> wrote in message
      news:c178e3e8.0 411030745.104cc 68c@posting.goo gle.com...[color=blue]
      > Hi,
      >
      > I have a recordset which pulls out specific customer names.
      > One of our customers have many branches, i.e:
      > Customer A Site 1
      > Customer A Site 2
      > Customer A Site 3
      > etc.....
      >
      > I have the following IF statement, and want to catch all of the Customer A
      > names...
      >
      > If RS("CustomerNam e") like Customer A * then........
      >
      > I just want to catch all customer names starting with 'Customer A'.
      >
      > I'm sure this statement will work, i'm just missing a quote or something
      > ??
      >
      > Appreciate your help
      >
      > David[/color]


      Comment

      • David Gordon

        #4
        Re: Using LIKE with IF....


        Aaron,


        Cheers,
        that did the trick !

        Why did'nt I think of something so simple.....Doh !


        Great Work


        Thanks again.


        *** Sent via Developersdex http://www.developersdex.com ***
        Don't just participate in USENET...get rewarded for it!

        Comment

        Working...