Compare Encrypted String Using SQL

I have some data encrypted in SQL.
I want to use the LIKE command in SQL to compare a submitted form value to an encrypted value in the table.
How can I do this?
<cfquery>
SELECT *
FROM table
WHERE decrypt(name,key) = '#form.name#'
</cfquery>
Of course the decrpyt does not work in the example above as it gives an error. But how can I achieve the results without error?
Thanks.
Chuck

Making some headway here.
Here is what I have so far.
<cfquery name="cust" datasource="#DSN#" username="#USER#" password="#PASS#">
SELECT *
FROM customer
</cfquery>
<CFLOOP query="cust">
<CFSET temp = QuerySetCell(cust,"decust_co","#Decrypt(cust.cust_co,variable.ekey)#",#cust.currentrow#)>
<CFSET temp = QuerySetCell(cust,"decust_last","#Decrypt(cust.cust_last,variable.ekey)#",#cust.currentro w#)>
<CFSET temp = QuerySetCell(cust,"decust_first","#Decrypt(cust.cust_first,variable.ekey)#",#cust.current row#)>
</CFLOOP>
[Didn't think you would have to loop the QuerySetCell's, but you do
<cfquery dbtype="query" name="decust">
SELECT *
FROM cust
WHERE custid > 0
AND (decust_co LIKE '%#search#%'
OR decust_last LIKE '%#search#%'
OR decust_first LIKE '%#search#%'
OR acct_no LIKE '%#search#%')
ORDER BY decust_co
</cfquery>
OK...the part that is not working is my wildcard seach values. When I send a search variable of a single letter - C, M, H, etc...it will bring back results. If I send a NULL search variable - it will bring back all results...when I send a search variable with more than two characters - zero results. I am using two characters like "Ch" and one of the values is "Chuck". It should bring back a result. This query worked fine, prior to encrypting this data. I have verified the data in the QuerySetCell variables above are populating and decrypting correctly when I dumped the query.
Any idea?

Similar Messages

  • Trying to compare 2 strings using sql...should be an easy one

    I have a String variable named 'code' that = "xyz". I have "xyz" in my DB under the userCodes column. And I have the following in my Java code:
    String query = "SELECT userCodes FROM accounts";
    ResultSet rs = stmt.executeQuery(query);
    while (rs.next()) {
    thisCode = rs.getString("userCodes");
    if (thisCode == code) { System.out.println("ITS THE SAME CODE"); }The problem is that Java is not recognizing thisCode as being equal to code, when they clearly are equal. Could someone please tell me why the two strings are not equal?
    Thanks.

    Since strings are objects you have to use equals metho to test the equality of the strings.
    Or in sql you can do this by adding a where clause
    PreparedStatement ps = connection.prepareStatement("SELECT userCode FROM accounts WHERE userCode=?");
    ps.setString(1,code);
    ResultSet rs = ps.executeQuery();
    ...

  • How do count how many 'A' s in this string using sql stmt?

    hi all,
    i have a string like 'AAAAARAMAAAAKRISHNAAAA'.
    in this ,i want to find out how many 'A's .
    how do find out this using select stmt.

    (length(s) - nvl(length(replace(s, 'A')), 0)) / length('A')but consider (by modifying the question slightly to "how do count how many 'AA' s in this string using sql stmt? ")
    SQL>  select (length('AAAAARAMAAAAKRISHNAAAA') - nvl(length(replace('AAAAARAMAAAAKRISHNAAAA', 'AA')), 0)) / length('AA') x from dual
             X
             6
    1 row selected.couldn't I argue that the result should be 10 as e.g. in
    SQL>  select * from xmltable('let $str := "AAAAARAMAAAAKRISHNAAAA"
                            let $search := "AA"
                            for $i in 1 to string-length($str)
                              where substring($str, $i, string-length($search)) = $search
                              return substring($str, $i, string-length($search))' columns x varchar2(10) path '.')
    X        
    AA       
    AA       
    AA       
    AA       
    AA       
    AA       
    AA       
    AA       
    AA       
    AA       
    10 rows selected.Matter of definition I suppose .... ;)
    btw. regexp_count also yields 6:
    SQL>  select regexp_count('AAAAARAMAAAAKRISHNAAAA', 'AA') x from dual
             X
             6
    1 row selected.

  • Need Help in Splitting a String Using SQL QUERY

    Hi,
    I need help in splitting a string using a SQL Query:
    String IS:
    AFTER PAINT.ACOUSTICAL.1..9'' MEMBRAIN'I would like to seperate this string into multiple lines using the delimeter .(dot)
    Sample Output should look like:
    SNO       STRING
    1            AFTER PAINT
    2            ACOUSTICAL
    3            1
    4            
    5            9" MEMBRAIN
    {code}
    FYI i am using Oracle 9.2                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    There's this as well:
    with x as ( --generating sample data:
               select 'AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN' str from dual union all
               select 'BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN' str from dual)
    select str,
           row_number() over (partition by str order by rownum) s_no,
           cast(dbms_xmlgen.convert(t.column_value.extract('//text()').getstringval(),1) as varchar2(100)) res
    from x,
         table(xmlsequence(xmltype('<x><x>' || replace(str,'.','</x><x>') || '</x></x>').extract('//x/*'))) t;
    STR                                                S_NO RES                                                                                                
    AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN                 1 AFTER PAINT                                                                                        
    AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN                 2 ACOUSTICAL                                                                                         
    AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN                 3 1                                                                                                  
    AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN                 4                                                                                                    
    AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN                 5 9" MEMBRAIN                                                                                        
    BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN          1 BEFORE PAINT                                                                                       
    BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN          2 ELECTRIC                                                                                           
    BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN          3 2                                                                                                  
    BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN          4                                                                                                    
    BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN          5 45 caliber MEMBRAIN      
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Insert String Using SQL Query

    Hi, EveryOne,
    I tried to insert(update) a string data type using Fixed SQL Query as, for a example:
    insert into Masters(MasterName) values([Param.1])
    In html form I enter a value in field and press button to call the function. But if enter in the field a String value - nothing inserted in table but if I enter Number - everything works fine. I tried to use commas but the effect is the same.
    Thnks,
    Serj

    Hello Sergey,
    Ryan's sql statement is right. The ' sign is used to mark the [Param.1] as a string.
    The sql statement (connection) is language independent, but you have to make sure that you mark up strings and timestamps in the correct way.
    In your first statement
         Masters(MasterName) values([Param.1])
    xMII will replace [Param.1] with the value you type in("yourvalue"). For strings("yourvalue") it will look like this
         Masters(MasterName) values(yourvalue)
    this should bring back a sql error. You can try it in another sql client.
    Hope this help as an explanation.
    Regards,
    Martin

  • Make a large string using sql

    Ok all I want to do is generate a string of length X.
    so to generate a 1000 character string of 'X's I'm doing the following:
    select replace ('X','Y',1000) from dualThis is Just giving me X.
    What am I doing wrong.

    Use LPAD/RPAD:
    select lpad('X', 1000, 'Y')
    ,      length(lpad('X', 1000, 'Y'))
    from dual;http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions082.htm#SQLRF00663
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions140.htm#SQLRF06103

  • How to split a string using sql

    Hi All,
    I've to write a query where I need to split a string, how this can be done? So let's say a column has value as 1,2,3,4,5 and I want to split this string and output it as:
    1
    2
    3
    4
    5
    Please advise.

    Lots of articles:
    Snap this user defined function too:
    CREATE FUNCTION [dbo].[ufn_SplitString_Separator](@InputStr VARCHAR(MAX), @Separator VARCHAR(1))
    RETURNS @tmpTable TABLE (OutputStr VARCHAR(MAX))
    AS BEGIN
    DECLARE @TmpPOS integer
    SET @TmpPOS = CHARINDEX(@Separator,@InputStr)
    WHILE @TmpPos > 0 BEGIN
    IF @TmpPos > 0 BEGIN
    INSERT INTO @tmpTable VALUES (LTRIM(RTRIM(SUBSTRING(@InputStr,1,@TmpPos-1))))
    SET @InputStr = SUBSTRING(@InputStr, @TmpPOS + 1, LEN(@InputStr) - @TmpPos)
    SET @TmpPOS = CHARINDEX(@Separator,@InputStr)
    END ELSE BEGIN
    INSERT INTO @tmpTable VALUES (LTRIM(RTRIM(@InputStr)))
    SET @TmpPos = 0
    END
    END
    IF LEN(@InputStr) > 0 BEGIN
    INSERT INTO @tmpTable VALUES (LTRIM(RTRIM(@InputStr)))
    END
    RETURN
    END
    GO
    And you can use like this:
    SELECT * FROM DBO.[ufn_SplitString_Separator]('1,2,3,4,5',',')
    "If there's nothing wrong with me, maybe there's something wrong with the universe!"

  • Splitting string using SQL

    Hi all,
    I have a column(address) which I have to split into 4 parts. This may contain 1 or more lines(separated by new line). How to split this.
    create table t(address varchar2(50));
    insert into t values('first'||chr(10)||chr(13)||'second');
    Antony Paul.

    Hi,
    My first guess would be a simple substr with an instr.
    Find the position of the chr(10) chr(13) combination and do a substring. It will not be very fast, but it will work.
    An alternitive is using a function to return the values you need.
    Jeroen

  • How to compare 2 dates in SQL Server 2000 DB using Java?

    How do you compare 2 dates in SQL Server 2000 DB using Java?
    Let's say we have two fields: Date Reported and Target Finish Date.
    Date Reported is 09-10-2004 09:55:55: PM
    Target Finish Date is 09-12-2004 11:59:59: PM
    What i want to happen is i want to convert both dates to days and get the difference of the two.
    can SQL Server 2000 DB do this?

    it doesnt wrk.
    ok here's what i did:
    iv tested a simple code for this case.
    I created a table name tblDate which has 3 columns namely date_ID, date_From (datatype datetime), date_To (datatype datetime).
    I inserted 1 row: date_ID has the value 1, date_From has the value 10/22/2004, and date_To has the value 10/24/2004.
    i run the java code below:
    int days = 0;
              String query = "SELECT date_From, date_To cast(date_From-date_To AS int) AS Diff FROM tblZoo WHERE date_ID = '1'";
              try
                   DBConnect db = new DBConnect();
                   db.openCon();
                   ResultSet rs = db.execute(query);
                   while(rs.next())
                        days = rs.getInt("Diff");
                   db.closeCon();                         
              catch (Exception ex)
                   System.out.println("Error on Execution: " + ex);
              return days;___________
    an error occurred: Error on Execution: java.lang.nullpointerexception

  • How can i encrypt an ddecrypt a string using java

    hai,
    can anybody know how to encrypt and decrypt a string using java..
    please if anybody help me with a small example and with code
    thanks
    ravi chandra

    hi,
    of course there are better ways to crypt your code, but the following 2 functions do their job....
    as far as i know java has an own api for crypting stuff.
    private String GetEncryptedString(String aCryptedString)
    String result = "";
    String str = aCryptedString;
    int[] asciiArray = new int[str.length()];
    for(int i = 0; i < asciiArray.length; i++)
    asciiArray[i] = (int)str.charAt(i);
    char tempChar = (char)(asciiArray[i]+3);
    result = result+tempChar;
    return result;
    private String GetDecryptedString(String aString)
    String result = "";
    String str = aString;
    int[] asciiArray = new int[str.length()];
    for(int i = 0; i < asciiArray.length; i++)
    asciiArray[i] = (int)str.charAt(i);
    char tempChar = (char)(asciiArray[i]-3);
    result = result+tempChar;
    return result;
    andi

  • How to Compare two strings in PL/SQL

    Hi All,
    I need to compare two strings whether they are equal or not in PL/SQL.Is there any function to comparing the strings.

    Yes, the = sign.
    Are you after something like:
    IF v_string1 = v_string2 THEN
    ELSE
    END IF;?
    Edited by: Boneist on 27-Aug-2009 11:41

  • Count the number of times a character is in a string using pl/sql

    I need to count the number of times ":" appers in the string ":XXX:CCC:BBB:".
    I have sound some solution using SQL but I do not want the context switch.
    Also I am on 10g so I can not use REGEXP_COUNT.
    Any help would be great.

    Hi,
    length(REGEXP_REPLACE(':XXX:CCC:BBB:','[[:alnum:]]'))counts all kinds of punctuation, spaces, etc., not just colons. Change any (or all) of the colons to periods and it will still return 4. Use '[^:]' instead of '[[:alnum:]]' if you really want to count just colons.
    Also, "SELECT ... FROM dual" is usually needed only in SQL*Plus or similar front end tools. In PL/SQL, you can call functions without a query, like this:
    x := NVL (LENGTH (REGEXP_REPLACE (txt, '[^:]')), 0);

  • SQL Function to compare 2 strings

    Hi All
    Is there any SQL function to compare 2 strings?

    If you are looking for a character by character comparison then you would have to do something like...
    SQL> ed
    Wrote file afiedt.buf
      1  WITH T AS (select 'THIS IS MY 1ST STRING' string1, 'THIS IS MY 2ND String Bob' string2 from dual)
      2  --
      3  select s1ch, s2ch, decode(s1ch,s2ch,'Match','Mismatch') as compare
      4  from (
      5        select rn, substr(string1,rn,1) as s1ch, substr(string2,rn,1) as s2ch
      6        from t, (select rownum rn from t connect by rownum <= greatest(length(string1), length(string2)))
      7       )
      8* order by rn
    SQL> /
    S S COMPARE
    T T Match
    H H Match
    I I Match
    S S Match
        Match
    I I Match
    S S Match
        Match
    M M Match
    Y Y Match
        Match
    1 2 Mismatch
    S N Mismatch
    T D Mismatch
        Match
    S S Match
    T t Mismatch
    R r Mismatch
    I i Mismatch
    N n Mismatch
    G g Mismatch
        Mismatch
      B Mismatch
      o Mismatch
      b Mismatch
    25 rows selected.
    SQL>

  • Find Connection String used by SQL Server Management Studio

    I am having problems getting my VS C# .NET application to connect to a SQL Server Database, even though I can connect to it (on the same machine) using SQL Server Management Studio.
    Is there any way I can find the connection string that SQL Server Management Studio generates when it connects?

    Hi,
    As you have Visual Studio on your machine, I think we can also use the Visual Database Tools of Visual Studio to generate the connection string.
    Please:
    1. Create a new data connection to the SQL Server database in the
    Server Explorer of Visual Studio
    2. After the connection is established, right-click on the connection name and select
    Properties. There is an item called Connection String in the
    Properties window.
    Reference:
    How to: Add New Data Connections in Server Explorer/Database Explorer 
    http://msdn.microsoft.com/en-us/library/3d1wkhas.aspx
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.

  • How to get Connection string for Sql Server Installed ( using Gallary ) on Azure VM ?

    Installed Azure VM From gallary with Sql Server 2012, even after allowing 1433 port through firewall, still cant get access to Sql Server from outside vm, So please provide steps for getting exact ServerName for connecting Sql Server on VM for connecting
    from Visual Studio Application.
    Thanks.

    Hi,
    You can check the DNS name of the VM in the VM instance page of the Azure management portal.
    In addition, you can also refer to the third-party article below:
    http://thomaslarock.com/2014/02/connect-to-a-windows-azure-vm-using-sql-server-management-studio/
    ( Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please
    make sure that you completely understand the risk before retrieving any suggestions from the above link.)
    Best regards,
    Susie
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact [email protected]

Maybe you are looking for

  • User account? urgent help

    Ok so i bought my computer second hand and I foolishly tried to change the details on it without knowing what i was doing. My problem is that i was playing around with the user accounts and the next time i turned my computer on i lost everything on m

  • Beginner installing SQL Server 2014 for Excel Data Mining

    Hello, I'm a complete beginner with servers but Im desperately trying to gain access to the SQL server for use with the data mining addin for excel. Could someone please help. When I try to make a connection in Excel by choosing DATA MINING> <No Conn

  • Ring Constant: 30 values max? LV 8.0

    Hey all, I'm trying to use 50 pairs but it's clipping me off at 30. Is there a fix for this? Thanks.  Solved! Go to Solution.

  • ITunes only works when offline.

    Keep getting Error message "iTunes has stopped working". But if I disconnect the internet it works great. Anyone know how to solve this?

  • Minimum number of ratings needed to get a rating?

    I'm a newb with 3 ratings.  What's the threshold number for iTunes to give an overall average rating?