Using LIKE with IF....

Discussion in 'ASP General' started by David, Nov 3, 2004.

  1. David

    David Guest

    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("CustomerName") 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
    David, Nov 3, 2004
    #1
    1. Advertising

  2. 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("CustomerName")
    if left(lcase(strDB), 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...

    --
    http://www.aspfaq.com/
    (Reverse address to reply.)




    "David" <> wrote in message
    news:...
    > 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("CustomerName") 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], Nov 3, 2004
    #2
    1. Advertising

  3. David

    David Gordon Guest

    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!
    David Gordon, Nov 3, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex
    Replies:
    0
    Views:
    405
  2. Blmn
    Replies:
    0
    Views:
    440
  3. Ittay Dror
    Replies:
    1
    Views:
    437
    Ittay Dror
    Jul 29, 2004
  4. KB
    Replies:
    5
    Views:
    768
    Steven D'Aprano
    Jul 31, 2005
  5. Patrick Kowalzick
    Replies:
    5
    Views:
    470
    Patrick Kowalzick
    Mar 14, 2006
Loading...

Share This Page