SQL Not Like ^ Character

Hello All,
Can you please help me with a SQL Transaction TSQL query.
The rules are these
- the query is a hard coded "LIKE" statement - I dont not have the ability to pass the word NOT.
- I wish to return all records where the first two characters of a field are not PA
Lets say the field "WORD" contains the following...
CARPET
PARTNER
PORTION
SALTS
PARAMETER
FAULT
I want to return all rows where the first two characters are NOT PA. (So exclude Partner and Parameter)
As the application passes everything in the query as a LIKE - I can only use the ^ parameter.
The where clause is hardcoded something along the lines "WHERE WORD LIKE @PARAMETER"
I have tried using a number of variable but cannot work out how to use the ^ character without eliminating records I actually want retrieved.
If I pass '%[^P]_________'  - It removes the rows I want but also removes PORTION which I actually want
If I pass %[^P][^A]_________' It removes all rows and returns nothing
Can someone please aide me with what may pass and only exclude words that start with PA.
Many Thanks

Try something below(you can have your own search conditions)
DECLARE @Sample TABLE(string VARCHAR(100));
INSERT INTO @Sample
values('CARPET'),('PARTNER'),('PORTION'),('SALTS'),('PARAMETER'),('FAULT')
Select string From @Sample where
string LIKE '%[^P][^A]'
Select string From @Sample where
string LIKE '[^P]%'
EDIT: Try the below:
DECLARE @Sample TABLE(string VARCHAR(100));
INSERT INTO @Sample
values('CARPET'),('PARTNER'),('PORTION'),('SALTS'),('PARAMETER'),('FAULT')
Select string From @Sample
where PATINDEX('[^PA]%',string) = 1 or charindex('PA',string)=0

Similar Messages

  • Not Like in SQL not working

    Trying to use not like in the following sql:
    select *
    from respondents
    where sample_id = 00000001
    and email not like '%cccp.org%';
    Right now, I'm getting back 51 rows, but 1/2 of the rows have the wrong domain in the email fields, and I need to filter all of the wrong ones, except cccp.org.
    There was a thread,
    NOT LIKE
    And I tried that, but not getting the correct results.
    thanks

    Given a simple table like:
    SQL> SELECT * FROM t;
    EMAIL
    [email protected]
    [email protected]
    [email protected]
    [email protected]
    [email protected]
    [email protected] WHERE email NOT LIKE '%cccp.org%' will return:
    SQL> SELECT email FROM t
      2  WHERE email NOT LIKE '%cccp.org%';
    EMAIL
    [email protected]
    [email protected]
    [email protected] is exactly what you asked for. However, this statement "1/2 of them have the wrong email domain, like .edu and .com email domains" seems to contradict the predicate. Do you really want something more like:
    SQL> SELECT email FROM t
      2  WHERE email LIKE '%cccp.org%';
    EMAIL
    [email protected]
    [email protected]
    [email protected]
    John

  • Performance issue with NOT LIKE 'VA%' in Sql Query

    I'm fetching vendor details from po_vendor_sites_all , in the where clause i use vendor_site_code NOT LIKE 'VA%'. Database:10g
    NOT LIKE is reducing the performance, any other option to increase the performance.
    Any suggestions?
    Thanks
    dow005

    Assuming a fairly even distribution of vendor_site_codes and assuming a LIKE 'VA%'
    would pick up 1% of the rows and assuming an index on vendor_site_codes
    and a reasonable clustering we might expect that query to use an index.
    Your query is NOT LIKE 'VA%' which implies picking up 99% of the rows = Full table scan.
    The only option I can think of is to use parallelism in your query (if the system has the
    power to handle it) or perhaps use more where clause restrictions on indexed column(s)
    to reduce the number of rows picked up.
    I've had to assume a lot of things as you don't give any info about the table and data.
    If you could provide more information we might be able to help more.
    See SQL and PL/SQL FAQ
    Edited by: Paul Horth on 02-May-2012 07:12

  • Not Like statement in Crystal?

    In SQL server there is a statement that goes along the lines of (field1) not like '09%'
    In Crystal Reports there is a statement "Like".  Is there any statement in Crystal that is "Not Like"?
    I'm trying to get a wildcard of 09 to work in Crystal so far I have......
    (field1) <> "09*"
    But it needs to be something like the following ........
    (field1) not like "09*"
    Does Crystal have a Not Like statement?  What are my choices if Crystal does not have that statement?
    Thanks

    I'm looking for anything that does not contain any thing like "09".  The actual "09" field is "09xx", and the report will need to pull back everything that is not "09"
    I used the * symbol to try and do a wildcard that would not pull back anything that is like "09".
    I was wondering if the * symbol was Crystal Reports answer to "Not Like"?

  • Works in sql not in apex: ORA-02049 distributed transaction waiting lock

    Hi,
    I get this error
    failed to parse SQL query:
    ORA-02049: timeout: distributed transaction waiting for lockwhen trying to run this query from it's page. But it works fine if I run it in the SQL console...
    failed to parse SQL query:
    ORA-select distinct n.notif_no,
           n.maint_work_centre,
           n.maint_work_centre_text,
           n.raised_by,
           n.notif_text,
           (select  (SAP_LONG_TEXT.NOTIFICATION_TEXT_1||SAP_LONG_TEXT.NOTIFICATION_TEXT_2||SAP_LONG_TEXT.NOTIFICATION_TEXT_3||SAP_LONG_TEXT.NOTIFICATION_TEXT_4||SAP_LONG_TEXT.NOTIFICATION_TEXT_5||SAP_LONG_TEXT.NOTIFICATION_TEXT_6||SAP_LONG_TEXT.NOTIFICATION_TEXT_7||SAP_LONG_TEXT.NOTIFICATION_TEXT_8||SAP_LONG_TEXT.NOTIFICATION_TEXT_9||SAP_LONG_TEXT.NOTIFICATION_TEXT_10||SAP_LONG_TEXT.NOTIFICATION_TEXT_11||SAP_LONG_TEXT.NOTIFICATION_TEXT_12||SAP_LONG_TEXT.NOTIFICATION_TEXT_13||SAP_LONG_TEXT.NOTIFICATION_TEXT_14||SAP_LONG_TEXT.NOTIFICATION_TEXT_15||SAP_LONG_TEXT.NOTIFICATION_TEXT_16||SAP_LONG_TEXT.NOTIFICATION_TEXT_17||SAP_LONG_TEXT.NOTIFICATION_TEXT_18||SAP_LONG_TEXT.NOTIFICATION_TEXT_19||SAP_LONG_TEXT.NOTIFICATION_TEXT_20||SAP_LONG_TEXT.NOTIFICATION_TEXT_21||SAP_LONG_TEXT.NOTIFICATION_TEXT_22||SAP_LONG_TEXT.NOTIFICATION_TEXT_23||SAP_LONG_TEXT.NOTIFICATION_TEXT_24||SAP_LONG_TEXT.NOTIFICATION_TEXT_25||SAP_LONG_TEXT.NOTIFICATION_TEXT_26||SAP_LONG_TEXT.NOTIFICATION_TEXT_27||SAP_LONG_TEXT.NOTIFICATION_TEXT_28||SAP_LONG_TEXT.NOTIFICATION_TEXT_29||SAP_LONG_TEXT.NOTIFICATION_TEXT_30||SAP_LONG_TEXT.NOTIFICATION_TEXT_31||SAP_LONG_TEXT.NOTIFICATION_TEXT_32||SAP_LONG_TEXT.NOTIFICATION_TEXT_33||SAP_LONG_TEXT.NOTIFICATION_TEXT_34||SAP_LONG_TEXT.NOTIFICATION_TEXT_35||SAP_LONG_TEXT.NOTIFICATION_TEXT_36||SAP_LONG_TEXT.NOTIFICATION_TEXT_37||SAP_LONG_TEXT.NOTIFICATION_TEXT_38||SAP_LONG_TEXT.NOTIFICATION_TEXT_39||SAP_LONG_TEXT.NOTIFICATION_TEXT_40||SAP_LONG_TEXT.NOTIFICATION_TEXT_41||SAP_LONG_TEXT.NOTIFICATION_TEXT_42||SAP_LONG_TEXT.NOTIFICATION_TEXT_43||SAP_LONG_TEXT.NOTIFICATION_TEXT_44||SAP_LONG_TEXT.NOTIFICATION_TEXT_45||SAP_LONG_TEXT.NOTIFICATION_TEXT_46||SAP_LONG_TEXT.NOTIFICATION_TEXT_47||SAP_LONG_TEXT.NOTIFICATION_TEXT_48||SAP_LONG_TEXT.NOTIFICATION_TEXT_49||SAP_LONG_TEXT.NOTIFICATION_TEXT_50) from sap_long_text@genadm where sap_long_text.notification = n.notif_no) "long",
           n.notif_date,
           n.funct_loc,
           n.order_no,
           n.notif_status,
           n.room,
           n.notif_type
    from   notifications@amt n, SAP_LONG_TEXT@genadm
    where  instr(':'||:P9_NOTIFTYPE||':',':'||n.NOTIF_TYPE||':')>0 and
           instr (':'||:P9_SITE||':',':'||n.site||':') > 0 and
           n.notif_date BETWEEN :P9_DATEFROM and :P9_DATETO and
           n.notif_status not like '%NOCO%'I've had this error before but I don't remember why/what happened. The page has been working fine, the error just randomly cropped up today.
    And a secondary question, is there a better way to write the query (it's a copy/paste from an older query). That select within the select is ugly...

    Hello,
    Take a look at the following thread -
    help ORA-02049
    Is it really necessary that you always query across the DBLink? Is using local materialized views not an option for you?
    John.
    http://jes.blogs.shellprompt.net
    http://apex-evangelists.com

  • Java.sql.SQLexception: Invalid character encountered in: failAL32UTF8Conv

    I have an Oracle 9i database set to use NLS_CHARACTERSET - AL32UTF8. This database is running on a LINUX server with LANG=en_US.UTF-8. The final piece is an application running on WebLogic. Until recently, I had no problems. Now I receive "invalid character" errors on the WebLogic console when trying to create users via the application using the letters f, o, and r. Does anyone know what direction to look in to resolve this problem? The JDBC driver should be using UTF-8 by default and I am not sure where else to look.
    The exact error we are getting is:
    java.sql.SQLexception: Invalid character encountered in: failAL32UTF8Conv
    I noticed on this forum someone else who had this problem was told to update to the latest Oracle thin driver. We are already using the latest ojdbc14.zip. Do you have any suggestions beyond that?
    FYI - We are running BEA WebLogic Server 8.1.

    Fee fee wrote:
    I encounter the following error while I establish connection with my Oracle 9.2.0.1.0
    DB server. DB is now using ATL32UTF8 and national character as UTF16.
    I see somebody encounter this error before. Any idea ???Hi. You should download and use Oracle's latest thin driver, as opposed to the
    driver we ship with our product. The shipped one was the best there was at the time
    but oracle has since fixed other bugs, and this may be one.
    Joe
    >
    >
    Cheers,
    Feefee
    DriverManager.initialize: jdbc.drivers = null
    JDBC DriverManager initialized
    registerDriver: driver[className=oracle.jdbc.driver.OracleDriver,oracle.jdbc.driver.OracleDriver@22926e]
    DriverManager.getDriver("jdbc:oracle:thin:@192.168.9.180:1521:cchs")
    trying driver[className=oracle.jdbc.driver.OracleDriver,oracle.jdbc.driver.OracleDriver@22926e]
    getDriver returning driver[className=oracle.jdbc.driver.OracleDriver,oracle.jdbc.driver.OracleDriver@22926e]
    SQLException: SQLState(null) vendor code(17055)
    java.sql.SQLException: Invalid character encountered in: failAL32UTF8Conv
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
    at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:1130)
    at oracle.jdbc.dbaccess.DBConversion.failAL32UTF8Conv(DBConversion.java:2762)
    at oracle.jdbc.dbaccess.DBConversion.javaCharsToAL32UTF8Bytes(DBConversion.java:2678)
    at oracle.jdbc.dbaccess.DBConversion.stringToAL32UTF8Bytes(DBConversion.java:2624)
    at oracle.jdbc.dbaccess.DBConversion.stringToAccessCharBytes(DBConversion.java:391)
    at oracle.jdbc.dbaccess.DBConversion.StringToCharBytes(DBConversion.java:456)
    at oracle.jdbc.ttc7.O3log.setSessionFields(O3log.java:796)
    at oracle.jdbc.ttc7.O3log.<init>(O3log.java:124)
    at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:256)

  • Why does TO_CHAR not like me adding a fraction then specifying FF?

    Why does TO_CHAR not like me adding a fraction?
    SQL> SELECT TO_CHAR(TO_TIMESTAMP('1/1/2012', 'DD/MM/YYYY') + .733409047, 'HH24:MI:SS') FROM Dual;
    TO_CHAR(
    17:36:07
    SQL> SELECT TO_CHAR(TO_TIMESTAMP('1/1/2012', 'DD/MM/YYYY') + .733409047, 'HH24:MI:SS.FF') FROM Dual;
    SELECT TO_CHAR(TO_TIMESTAMP('1/1/2012', 'DD/MM/YYYY') + .733409047, 'HH24:MI:SS.FF') FROM Dual
    ERROR at line 1:
    ORA-01821: date format not recognized
    -- NUMTODSINTERVAL() saves the day.
    SQL> SELECT TO_CHAR(TO_TIMESTAMP('1/1/2012', 'DD/MM/YYYY') + NUMTODSINTERVAL(.733409047, 'DAY'), 'HH24:MI:SS.FF') FROM Dual;
    TO_CHAR(TO_TIMESTA
    17:36:06.541660800

    Hi,
    Date arithmetic only works with DATEs.
    If you want to do something similar with TIMESTAMPs, use NUMTODSINTERVAL:
    SELECT  TO_CHAR ( TO_TIMESTAMP ('1/1/2012', 'DD/MM/YYYY') + NUMTODSINTERVAL (.733409047, 'DAY')
              , 'HH24:MI:SS.FF'
    FROM      dual
    ;Here's exactly what's happending:
    When you say "d + n", d is supposed to be either a NUMBER or a DATE. When you pass any other datatype, Oracle tries to convert d to either a NUMBER or a DATE. In this case, d was a TIMESTAMP; Oracle realized that it could convert that TIMESTAMP into a DATE, and did so. The 1st argument to TO_CHAR, therefore, was a DATE, but '.FF' only works with TIMESTAMPs.
    There are a couple of things about how Oracle handles this that I find annoying, but I don't know of any better work-around.
    Edited by: Frank Kulash on Feb 16, 2012 1:39 PM

  • Question about not like operator

    HI,
    This where clause omitting ABC% , but I wanted to exclude some conditions I want my sql to return COLUMNA = 'ABCD' but exclude everything else 'ABC%'
    how do I fix this?
    WHERE COLUMNA NOT LIKE '%ABC'
    AND COLUMNA NOT LIKE 'ABC%'
    AND COLUMNA NOT LIKE '%XYZ'
    AND COLUMNA NOT LIKE 'XYZ%'
    Expected result:
    ABCD
    AAAA
    BBBB
    etc

    Hi,
    Here's one way:
    WHERE   COLUMNA NOT LIKE '%ABC'
    AND      (   COLUMNA NOT LIKE 'ABC%'
         OR  COLUMNA  =          'ABCD'
    AND      COLUMNA NOT LIKE '%XYZ'
    AND      COLUMNA NOT LIKE 'XYZ%'

  • Alternate for NOT LIKE....

    I am using NOT LIKE in sql query....it is running gud in dev instance,But in prod instance it is causing performance issue.
    can any one pls suggest alternate for NOT LIKE.
    But in dev n prod having same data.
    Thanks,
    Sai

    Hi Saichand,
    well, actually what do you expect? ;)
    You ask the DB to filter out specific lines and this takes time.
    What worries me is the fact that it performs fine on the development environment, but runs slow on the production environment. Did you find out what the reason for this is? Is the prod system loaded too heavily?
    There are many alternatives for "NOT LIKE". Within SQL and even outside of SQL. You can do the filtering in the final application even. Would not recommend this, but sometimes it's faster to just stream the data to the final application and to the processing there (if the processing takes lot of CPU and your DB is anyway loaded already too much).
    I'd try to find out why the dev is faster than the prod env. Normally it should be the way round ;)
    regards,
    David.

  • Modifying tool features like character size

    If I have multiple files open, only for the latest one I have opened, the tool features like character size can be modified. For the files i had opened previously opened and which are still open, suddenly the opportunity to modify the tool features, right after the moment I have open a new pdf-File with Acrobat.
    Can that problem be overcome ?
    System: Adobe Acrobat 9, Microsoft Windows 7, 64-bit

    It is up to Juno to enable Midas, the Rich Text Editor which is built into Firefox, with one little line of code on every web page that has RTE for IE. There's nothing that you can do to turn that feature on your self, it has to be coded on each web page that has Rich Text Editing.
    http://www.mozilla.org/editor/midas-spec.html <br />
    http://kb.mozillazine.org/Midas
    Their ignorance probably lies with their staff programmers only knowing how to do it for IE ''(their training and certificates are probably from the Microsoft cabal)'', and not realizing that Gecko and WebKit apps each have their own Rich Text Editor's, which require their own small line of code to enable those Editor's.

  • Make tables, views etc, aviable for public users, how could sql look like?

    Hey specialists,
    I produced under my username several tables, views and sequenzes. How could sql or Psql look like to create for all items a public synonym.
    where could I read more information about giving privilegs for tables etc to other users, for instance in dba-studio
    regards
    robert

    Hi!
    Create a sql script for sql*plus like:
    set head off echo off feedback off pagesize 999 line 120 trimsp on
    spool crepsn.sql
    select 'create public synonym ' || object_name || ' for '|| object_name || ';' || chr(10)
    from  user_objects
    where object_type in ( 'TABLE', 'VIEW', 'SEQUENCE', 'PACKAGE', 'PROCEDURE', 'FUNCTION' )
    and   object_name not like 'BIN$%'
    and   object_name not in ( select synonym_name
                               from   sys.dba_synonyms
                               where  owner = 'PUBLIC'
                               and    synonym_name = object_name
                               and    table_owner =  user )
    order by object_type, object_name
    spool off
    prompt creating Public Synonyms
    set termout on feedback on
    @crepsn
    set echo offThis creates public synonyms for the given object types of objects the current user is the owner of.
    If you get an error that a public synonym is already defined, the obectname
    is already in use by another user in the database.
    After this you have to give other users / public access to your objects via grants.
    Regards

  • I use keynote 5.1 and am bombarded with popups asking me to update to KN 6.  I tried 6 after upgrading to Maverick. Do not like it.

    I use keynote 5.1 and love it.  I tried Keynote 6 and do not like it.
    My problem is that I am bombarded by popups asking me to
    update to Keynote 6
    This reduce my work speed to a snails pace.
    Would be most delighted to find a solution to the problem.
    Thanks

    Is there a sim in the iPhone?
    Has the iPhone been jailbroken or modified to work with other
    than the original wireless provider?
    If you can get that far, what does it say when you look at
    Settings=>General=>About=>Carrier?

  • I have upgrade ios 6 to ios7 on my iphone 5.  I do NOT like it.  I want to come back to the previosu version.  why is it so complicated.  Why can I not find the instruction strait from apple? This is the worst possible upgrade ever.

    I have upgrade ios 6 to ios7 on my iphone 5.  I do NOT like it at all.   I want to come back to the previous version.  why is it so complicated? Why can I not find the instruction strait from apple? This is the worst possible upgrade ever.  It make me think of when ericsson got sold to Sony....drastic PC change.
    I would like to have simple instruction on how to downgrade.
    It feel like a change that I did not ask for , ok I push the upgrade buttom, but really this is the worst update aver!
    HELP!

    iPhone User Guide (For iOS 7 Software)Sep 20, 2013 - 23 MB

  • I really do not like the new Photos app.  My iPhoto app is disabled in Finder.  How can I go back to iPhoto?

    My system just updated to OS X 10.10.3 and now Photos has replaced iPhoto.  My iPhoto has been disabled in Finder.  I really DO NOT like Photos.  Photos are no longer organized into "Events" and my Events labels are gone.  I also am not able to share photos via e-mail.  I tried to update iPhoto through the App Store, but got the message that it is not available in the US.  Then I got a message that said it was temporarily not available.  How can I get iPhoto back?

    now Photos has replaced iPhoto.  My iPhoto has been disabled in Finder.
    No, Photos did not replace iPhoto. It did not disable iPhoto. You updated to 10.10.3 before updating iPhoto to version that was compatible with Yosemite. That is why your older version is disabled.

  • How do i get my old itunes back? I upgraded new version and do not like it

    Please can someone help me.... I did a software update and it changed my itunes and i do not like it, can i get my old version back?
    Or can i access free music again? As i could listen to the radio before???? I cannot find it in the new version.

    It's been awhile since I've done something like this, but if I memory serves me, I believe you use the System Restore function to return your computer to the state it was in prior to installing iTunes 11.
    That should take it back to the last version of iTunes you'd installed. Of course, any other changes you've made to your system since then (e.g. other programs installed, etc.) will also be changed back.
    Not to sound like a jerk for referring you to Google like so many people online tend to do--but--I think there are instructions for the process of reverting to a previous version available online. I've done it in the past with IE 8 vs IE 9.

Maybe you are looking for