Using the LIKE operator with wildcards to match names

I am using SQL in ColdFusion 9 to match names in an MS Access 2003 database table.
The Visitors field of MyTable contains the name "Smith" in six records.
1. Smith Jones Wilson
2. Smith, Jones, Wilson
3. Smith(Jr.), Jones, Wilson
4. Jones Wilson Smith
5. Wilson Smith Jones
6. Smith
7. Smithson, Jones, Wilson
8. Jones, Wilson, Arrowsmith
To find out which records contain the name Smith (but not Smithson or Arrowsmith) I now need to write four "OR" lines:
WHERE MyField LIKE 'Smith[!a-zA-Z]%'  (finds only the Smiths in records 1, 2 and 3)
         OR MyField LIKE '%[!a-zA-Z]Smith'  (finds only the Smith in record 4)
       OR MyField LIKE '%[!a-zA-Z]Smith[!a-zA-Z]%' (finds only the Smith in record 5)
       OR MyField = 'Smith'   (finds only the Smith in record 6)
I would like to know how to combine these four lines into one which would find all six records containing Smith.
Thank you for your help.

As this is a SQL-specific question, you might be better off asking it on a SQL forum?  Does Access even support regexes?
For a CF the regex you'd be after "\bsmith\b".  You should read the Access regex reference to see if it supports this.  A CF regular expression is no use to you here as the comparison needs to be done on the DB,  not in CF.
Adam
Misread the question.  Revising.

Similar Messages

  • Select Performance problems using the 'like' operator

    I have a PL/SQL procedure that uses a cursor which contains a 'like' operator in the where clause. I have two database instances that are theoretically the same, however this code processes about 100,000 rows in 5 minutes on one database and 100,000 rows in several weeks on the other database. I know it is the 'like' operator that is causing the problem, but I don't know where to look in the database setup parameters as to what could be different between the two. Can someone point me in the right direction?

    I tried to think of another way to write the query, but I really need to use the wildcard option on the data I'm searching for. The system I'm working with attaches a suffix to the end of every ID (ie. '214-222-1234-0') The suffix ('-0') increments but the rest of the ID stays the same ('-1','-2',etc...), but I want to find all of the rows where the first 12 characters are the same, so I strip off the suffix and use a wildcard '%' in its place. I tried adding the SUBSTR() function to the left hand column of the where clause, but it was even slower than using the 'like' operator. I know its a sound query, I just can't figure out why it works fine on one database and not the other.

  • Using the LIKE operator

    How do I create a search parameter LIKE for a name?  I wrote this, and it's pulling in all the names, instead of only searching for whatever I entered in.  What did I do wrong?  Please help.
    {table.name_last} like ["*", {?Last Name}]
    Thank you,
    T

    I have never seen it written like this.  Are the * entered in the parameter selection?
    {table.name_last} like \"*\", {?Last Name}
    What does
    do in the formula?

  • LIKE Operator with Clobs

    Hi, Having Problems using the LIKE Operator with the Clob Datatype. Does any one know if its possible.
    Thanks
    Emer

    It's not possible.
    try use DBMS_LOB.INSTR instead...

  • How to use LIKE operator with PreparedStatement

    Hi, I need to execute a query with the LIKE operator, but using a PreparedStatement. Can I do this, and if so what must my SQL look like with the wildcard characters '%' or '_'?
    normal PS example: conn.prepareStatement("select * from mytable where name like ?");
    If I try: conn.prepareStatement("select * from mytable where name like ?%");
    I get: ORA-00911: invalid character
    If I try: conn.prepareStatement("select * from mytable where name like '?%'");
    I get: ORA-01006: bind variable does not exist
    I must use a PreparedStatement, as my variable may contain illegal characters (like '), and using PreparedStatement.setString(1, var) will automatically escape it for me.
    I could also use a normal Statement, but I need to escape my var ... is there a utility that will safely escape a String for an Oracle VARCHAR2??
    Thanks in advance,
    Stu Miller

    Hmm, it seems you are right...
    when my variable contains a '%' symbol, the PreparedStatement will NOT escape it, and thus it is treated like a wildcard. Therefore, I can just do
    pstmt.setString(1, var+"%");
    But, that may return more results than I'm asking for, as when 'var' contains a '%' symbol it is taken as a wildcard too.
    I need each character in my variable to be taken literally, and only add a wildcard at the end. Basically, I need a STARTSWITH operator ;-)
    It seems to me that escaping the sensitive characters in a String (which will differ depending on which operator is used), should be possible. I could write this, but I was hoping Oracle had already done it for me in some utility class.

  • Hi could you show or tell me how to unlock my iphone 5? I baught an iphone 6 plus and would like to use the iphone 5 with another carrier could anyone help me.

    hi could you show or tell me how to unlock my iphone 5? I baught an iphone 6 plus and would like to use the iphone 5 with another carrier could anyone help me.

    Ask the carrier it's locked to if they'll unlock it. Nobody else can.
    (117723)

  • I would like to know if is possible to use the old iSight with my powerbook (mid 2009)?

    I would like to know if is possible to use the old iSight with the macbook pro (mid 2009)?

    Hi,
    If the Mac has Firewire then you can use the External iSight
    (Other readers
    If you have Firewire 800  then you will need an adapter to use the Firewire 400 camera - Search for the word Adpater and see posts by EZ Jim for more details)
    Don't daisy-chain the camera with Hard Drives
    The camera only uses a data rate of 200Mbps and the differences in Hard Drive data speeds can be an issue.
    The External iSIght should work no matter what Firmware is on there currently.
    There is some evidence that having the 1.0.3 version (Open the System Profiler > Hardware > Firewire) on the device makes it more compatible/useable in later OS versions
    The Updater is included in Tiger and Leopard. 
    Hard Drive/System/Library/CoreServices/iSight Updater/iSight Updater.app
    An OS Update could "trigger" this to be run if you have Tiger
    It can also be run as a Standalone.
    It is Not present in Snow Leopard and although the documentation says this Firmware is an Audio update some people report that the camera needs the 1.0.3 Firmware to run.
    (that could simply be the "Flashing" the Memory involved resets it enough to work)
    10:22 PM      Wednesday; June 8, 2011
    Please, if posting Logs, do not post any Log info after the line "Binary Images for iChat"
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb( 10.6.7)
     Mac OS X (10.6.7),
    "Limit the Logs to the Bits above Binary Images."  No, Seriously

  • Why the 'LIKE' operator takes so much time to run?

    I have a table T with 3 columns and 3 indexes:
    CREATE TABLE T
    id VARCHAR2(38) NOT NULL,
    fid VARCHAR2(38) NOT NULL,
    val NVARCHAR2(2000) NOT NULL
    ALTER TABLE T ADD (CONSTRAINT pk_t PRIMARY KEY (id,fid));
    CREATE INDEX t_fid ON T(fid);
    CREATE INDEX t_val ON T(val);
    Then I have the following two queries which differ in only one place - the 1st one uses the '=' operator whereas the 2nd uses 'LIKE'. Both queries have the identical execution plan and return one identical row. However, the 1st query takes almost 0 second to execute, and the 2nd one takes more than 12 seconds, on a pretty beefy machine. I had played with the target text, like placing '%' here and/or there, and observed the similar timing every time.
    So I am wondering what I should change to make the 'LIKE' operator run as fast as the '=' operator. I know CONTEXT/CATALOG index is a viable approach, but I am just trying to find out if there is a simpler alternative, such as a better use of the index t_val.
    1) Query with '=' operator
    SELECT id
    FROM T
    WHERE fid = '{999AE6E4-1ED9-459B-9BB0-45C913668C8C}'
    AND val = '3504038055275883124';
    2) Query with 'LIKE' operator
    SELECT id
    FROM T
    WHERE fid = '{999AE6E4-1ED9-459B-9BB0-45C913668C8C}'
    AND val LIKE '3504038055275883124';
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=1 Card=1 Bytes=99)
    1 0 TABLE ACCESS (BY INDEX ROWID) OF 'T' (Cost=1 Card=1 Bytes=99)
    2 1 INDEX (RANGE SCAN) OF 'T_VAL' (NON-UNIQUE) (Cost=4 Card=12)

    I will for sure try to change the order of the PK and see whether there will be any impact to the performance.
    In our application, val is much closer to a unique value than fid. In the example query, the execution plan showed that the index on val was indeed used in the execution of the query. That's why the 1st query took almost no time to return (our table T has more than 6 million rows).
    I was hoping the 'LIKE' operator would utilize the t_val index effectively and provide similar performance to the '=' operator. But apparently that's not the case, or needs some tricks.

  • Using the LIKE keyword in a SQL query

    Does anyone have an example using the Database Connectivity Execute Query vi and the LIKE keyword? I would like to do something like:
    SELECT TestNum, TestType FROM tests WHERE DeviceType ='Paul_AF125_Ver1' AND DeviceID = 'Test1' AND (TestType LIKE "Cyclic Voltammetry*")
    It works fine if I say LIKE "Cyclic Voltammetry" (without the *) but if I put the * in there, I get no records.
    I'm using Microsofts SQL Server Desktop Engine (comes with Access).
    Thanks,
    Paul

    Paul-
    Thank you for contacting National Instruments. I don't have an example program, but I did find some information for you.
    LIKE - similar to.
    Using the LIKE command, you can use the wildcard symbol %. To find names starting with J : names LIKE 'J%'; Ending in s ? name LIKE '%S'; You can use more than one % charactor too : names LIKE '%sam%'; Also, LIKE is not case sensitive.
    What you have written, may work if you change the wildcard syntax from * to %.
    -Erik

  • How do I increase the maximum number of images I can acquire in a sequence using the IMAQ 1424 with 80 MB of onboard memory and a Duncan Tech camera?

    I've increased the maximum number of buffers to higher than I need, but I still cannot acquire more than 139 images with the Duncan Tech digital video camera before I get a memory lock error. Is there any way to increase the number of images I can acquire in a sequence using the IMAQ 1424 with 80MB of onboard memory?

    It sounds like you are already bypassing the onboard memory. If you weren't, you would only be able to acquire about 20 images.
    If I understand correctly, you do not convert the images until after you acquire them. This means each acquired image is 4.13 MB, and 139 images will take 574 MB of memory. I wouldn't be surprised if that was all the free memory available on a 1 GB machine. The operating system, LabVIEW and any other software running probably take up the rest of the memory. You might want to put your computer on a diet and minimize the number of other programs and utilities running. The only other option I see is getting more memory if possible.
    Is there a way that you can reduce the number of images you need to acquire? Pe
    rhaps skipping every other frame? Do you really need more than 139 images?
    Is it possible to acquire the images in monochrome? That would triple the number of images that you could acquire.
    Bruce
    Bruce Ammons
    Ammons Engineering

  • What exacly does filtering by the "like" operator do?

    I'm using Apex 3.1 and in my interactive report I'm using the "Filter" option from the action menu. What exactly does the "like" operator do?
    For example if I have a string "male" does the like operator search for all words
    %male
    male% or
    %male%
    Thanks!

    If you test it out you will see that the IRR simply wraps whatever you enter into standard SQL syntax. So, selecting 'Job' 'like' and entering 'MAN' returns no rows against the EMP Table. Changing that to 'Job' 'like' 'MAN%' returns 'MANAGER's and 'Job' 'like' '%MAN' returns 'SALESMAN's (excuse the improper grammar). Your users need to put the % where they want the wildcard. We also mention it in the Help available off the Actions Menu - "The expression is case sensitive and you can use % as a wild card (e.g. STATE_NAME like A%).
    Hope that helps -
    -- Sharon

  • Can I use a LIKE operator in an IF statement in a column formula

    This is what I have so far.
    CASE WHEN Opportunity."Sales Type" LIKE '*New Acct' THEN 'Sale to NEW Customer' END
    I want to display 'Sale to NEW Customer' if opportunity type contains the terms New Acct.

    Try this:
    CASE WHEN Opportunity."Sales Type" LIKE '%New Acct' THEN 'Sale to NEW Customer' END
    The LIKE operator requires a % wildcard rather than the * wildcard.
    Mike L.

  • Using the apple remote with garageband

    Can you use the apple remote with Garagband? I know there are apps that cost like iRed Lite, but are there other options?

    are there other options?
    the only other one i know of is Remote Buddy

  • Using the MacBook Pro with external Monitor and Keyboard

    This may be a dumb question, but here it goes anyway:
    Can I use the MacBook Pro with an external monitor and a bluetooth keyboard and mouse without having it opened all of the time ?
    I am planning to buy a MacBook for my wife and most of the time she will be using it at her home office.
    I don't want her to use the computer opened all of the time when she is actually looking at the separate screen and using a separate keyboard. Having the laptop opened will only accumulate dust and reduce the lifetime of the built in screen.
    What I would actually need is a kind of "docking station", but Apple doesn't make that - I know.
    So can the MacBook at least be operated without the internal screen powered on while it is closed?
    Thanks for your help
    Martin
    Message was edited by: mdopp

    Yes - it's called clamshell mode:
    http://support.apple.com/kb/HT3131

  • LabView (8.2) hangs when using I/O operations with traditiona​l NI-DAQ 7.4.4 after aborting LabView program

    Hello!
    We have the following problem:
    LabView (8.2) hangs when using I/O operations with traditional NI-DAQ 7.4.4 after aborting LabView program
    We freshly installed LabView 8.2 (2006) and NI-DAQ 7.4.4 on a PC running Windows XP (Service Pack 3). We built a larger vi that remotely controls a traditional NI-DAQ card (AT-AO-10) on a second PC via NI-VISA 5.0.3. We were successfully running this program until a power failure caused the first computer to crash. After this crash we were unable to start the program again: LabView freezes while loading the vi. LabView itself can be started but freezes when adding I/O operations from the NI-DAQ palette to a block diagram.
    We have tried to re-install NI-DAQ 7.4.4, but it did not help. We then re-installed all NI software, but still no improvement. In the end we decided to reinstall ALL software, first Windows XP, then LabView and finally NI-DAQ 7.4.4. This worked. However, after a few days of running the program we had to abort LabView via Windows Task manager and afterward we again experienced the same problem as before: LabView freezes when loading the program.
    Obviously, we cannot afford to reinstall Windows every time. Are there any known Windows XP / NI-DAQ issues that might cause the freezing of LabView? We would be very grateful for any idea.
    Best regards,
    Matthias

    Hello Sprice,
    Browse the shipping examples according to “Directory Structure” and then select
    DAQ to find the Traditional DAQ examples. 
    There a lot of examples that are written for counters (Counter >>
    daq-stc.llb >> Count Edges (DAQ-STC).vi). 
    What kind of signals are your photons creating?  Are they TTL compatible at a certain
    frequency?  You don’t care about overwriting
    your buffer?
    Respectfully,
    Rob F
    Test Engineer
    Condition Measurements
    National Instruments

Maybe you are looking for