+ Reply to Thread
Results 1 to 6 of 6

ODBC LIKE clause

  1. ODBC LIKE clause

    I'm trying to execute the following query within a Visual
    C++ program...

    SELECT LastName from Employees WHERE LastName LIKE ?

    In the C++ program, I use the SQLBindParameter() to
    associate to the ?. The SQLBindParameter() variable used
    contains 'A%' (without the single quote).

    This is a very simple statement, but constantly returns
    no data.

    I run this exact statement within a MS Access database
    connection, and it returns 4 records. The MS Access wild
    card is also 'A%'. I think there is a bug in the SQL
    Server ODBC, but I cannot confirm this.

    Using the SQL Trace doesn't tell me the translations
    being performed within the ODBC driver to confirm a bug.

    Help...please...

    Regards,

    Angelo

  2. Re: ODBC LIKE clause

    Hi Angelo,

    The SQL Trace (you are using SQL 7 ?) will tell you the command the SQL
    Servers sees. What does that look like?

    Also have you tried 'A*' or have you tired

    SELECT LastName from Employees WHERE LastName LIKE '?'

    Just some ideas, I hope you fix the issue.


    --
    I hope this helps
    regards
    Greg O MCSD
    http://www.ag-software.com/ags_scribe_index.asp. SQL Scribe Documentation
    Builder, the quickest way to document your database
    http://www.ag-software.com/ags_SSEPE_index.asp. AGS SQL Server Extended
    Property Extended properties manager for SQL 2000
    http://www.ag-software.com/IconExtractionProgram.asp. Free icon extraction
    program
    http://www.ag-software.com. Free programming tools



    "Angelo" wrote in message
    news:04ee01c3b861$09b06700$a301280a@phx.gbl...
    > I'm trying to execute the following query within a Visual
    > C++ program...
    >
    > SELECT LastName from Employees WHERE LastName LIKE ?
    >
    > In the C++ program, I use the SQLBindParameter() to
    > associate to the ?. The SQLBindParameter() variable used
    > contains 'A%' (without the single quote).
    >
    > This is a very simple statement, but constantly returns
    > no data.
    >
    > I run this exact statement within a MS Access database
    > connection, and it returns 4 records. The MS Access wild
    > card is also 'A%'. I think there is a bug in the SQL
    > Server ODBC, but I cannot confirm this.
    >
    > Using the SQL Trace doesn't tell me the translations
    > being performed within the ODBC driver to confirm a bug.
    >
    > Help...please...
    >
    > Regards,
    >
    > Angelo




  3. Re: ODBC LIKE clause

    Thanks for the reply...

    I'm using SQL 8. I will try the TRACE again. I've tried
    your other suggestions but still get the same results.

    Later,

    >-----Original Message-----
    >Hi Angelo,
    >
    >The SQL Trace (you are using SQL 7 ?) will tell you the

    command the SQL
    >Servers sees. What does that look like?
    >
    >Also have you tried 'A*' or have you tired
    >
    >SELECT LastName from Employees WHERE LastName LIKE '?'
    >
    >Just some ideas, I hope you fix the issue.
    >
    >
    >--
    >I hope this helps
    >regards
    >Greg O MCSD
    >http://www.ag-software.com/ags_scribe_index.asp. SQL

    Scribe Documentation
    >Builder, the quickest way to document your database
    >http://www.ag-software.com/ags_SSEPE_index.asp. AGS SQL

    Server Extended
    >Property Extended properties manager for SQL 2000
    >http://www.ag-software.com/IconExtractionProgram.asp.

    Free icon extraction
    >program
    >http://www.ag-software.com. Free programming tools
    >
    >
    >
    >"Angelo" wrote in

    message
    >news:04ee01c3b861$09b06700$a301280a@phx.gbl...
    >> I'm trying to execute the following query within a

    Visual
    >> C++ program...
    >>
    >> SELECT LastName from Employees WHERE LastName LIKE ?
    >>
    >> In the C++ program, I use the SQLBindParameter() to
    >> associate to the ?. The SQLBindParameter() variable

    used
    >> contains 'A%' (without the single quote).
    >>
    >> This is a very simple statement, but constantly returns
    >> no data.
    >>
    >> I run this exact statement within a MS Access database
    >> connection, and it returns 4 records. The MS Access

    wild
    >> card is also 'A%'. I think there is a bug in the SQL
    >> Server ODBC, but I cannot confirm this.
    >>
    >> Using the SQL Trace doesn't tell me the translations
    >> being performed within the ODBC driver to confirm a

    bug.
    >>
    >> Help...please...
    >>
    >> Regards,
    >>
    >> Angelo

    >
    >
    >.
    >


  4. Re: ODBC LIKE clause

    Could you post all the parameters for SQLBindParameter() method. I am
    pretty confident that 'A%' is the correct syntax

    Pete

    Angelo wrote:

    >I'm trying to execute the following query within a Visual
    >C++ program...
    >
    >SELECT LastName from Employees WHERE LastName LIKE ?
    >
    >In the C++ program, I use the SQLBindParameter() to
    >associate to the ?. The SQLBindParameter() variable used
    >contains 'A%' (without the single quote).
    >
    >This is a very simple statement, but constantly returns
    >no data.
    >
    >I run this exact statement within a MS Access database
    >connection, and it returns 4 records. The MS Access wild
    >card is also 'A%'. I think there is a bug in the SQL
    >Server ODBC, but I cannot confirm this.
    >
    >Using the SQL Trace doesn't tell me the translations
    >being performed within the ODBC driver to confirm a bug.
    >
    >Help...please...
    >
    >Regards,
    >
    >Angelo
    >
    >


    --

    You don't pay to get spam, why pay to clean it?
    Visit http://www.spammarshall.com to create an account for free





  5. Re: ODBC LIKE clause

    I'm probably saying something pretty dumb right now.. but how are you using
    ODBC?

    Why can you not simply (assuming you're using MS Visual C++ with MFC) do:

    CString sql;
    sql.Format(_T("SELECT LastName from Employees WHERE LastName LIKE %s",
    _T("A%%");
    rs.Open(sql...)

    Or something like that.. ?



    "Angelo" wrote in message
    news:04ee01c3b861$09b06700$a301280a@phx.gbl...
    > I'm trying to execute the following query within a Visual
    > C++ program...
    >
    > SELECT LastName from Employees WHERE LastName LIKE ?
    >
    > In the C++ program, I use the SQLBindParameter() to
    > associate to the ?. The SQLBindParameter() variable used
    > contains 'A%' (without the single quote).
    >
    > This is a very simple statement, but constantly returns
    > no data.
    >
    > I run this exact statement within a MS Access database
    > connection, and it returns 4 records. The MS Access wild
    > card is also 'A%'. I think there is a bug in the SQL
    > Server ODBC, but I cannot confirm this.
    >
    > Using the SQL Trace doesn't tell me the translations
    > being performed within the ODBC driver to confirm a bug.
    >
    > Help...please...
    >
    > Regards,
    >
    > Angelo




  6. Re: ODBC LIKE clause

    Here is a sample application that results in a zero
    records found eventhrough there are a number of records
    within the table.

    ================================
    #include
    #include
    #include
    #include

    #define DATABASE_CLAUSE "MPOS_SQLSERVER"
    #define USERNAME_CLAUSE ""
    #define PASSWORD_CLAUSE ""
    #define SELECT_CLAUSE "SELECT COUNT(*) from Customers
    WHERE LastName LIKE ? "
    #define LIKE_CLAUSE "A%"

    void main( void )
    {
    HENV hEnv = SQL_NULL_HENV;
    HDBC hDbc = SQL_NULL_HDBC;
    HSTMT hStmt = SQL_NULL_HSTMT;
    long lValue = 0;
    SQLINTEGER sqlNull = 0;
    SQLINTEGER sqlStrLen = SQL_NTS;
    SQLUINTEGER sqlColumnLen = strlen( LIKE_CLAUSE );
    SQLINTEGER sqlBufferLen = strlen( LIKE_CLAUSE );
    SQLINTEGER sqlValue = 0;

    if ( ! SQL_SUCCEEDED( SQLAllocEnv( &hEnv )))
    printf( "Error in SQLAllocEnv()\n" );
    else if ( ! SQL_SUCCEEDED( SQLAllocConnect( hEnv,
    &hDbc )))
    printf( "Error in SQLAllocConnect()\n" );
    else if ( ! SQL_SUCCEEDED( SQLConnect( hDbc,
    (SQLCHAR *)
    DATABASE_CLAUSE, SQL_NTS,
    (SQLCHAR *)
    USERNAME_CLAUSE, SQL_NTS,
    (SQLCHAR *)
    PASSWORD_CLAUSE, SQL_NTS )))
    printf( "Error in SQLConnect()\n" );
    else if ( ! SQL_SUCCEEDED( SQLAllocStmt( hDbc,
    &hStmt )))
    printf( "Error in SQLAllocStmt()\n" );
    else if ( ! SQL_SUCCEEDED( SQLPrepare( hStmt,
    (SQLCHAR *)
    SELECT_CLAUSE,
    SQL_NTS )))
    printf( "Error in SQLPrepare()\n" );
    else if ( ! SQL_SUCCEEDED( SQLBindParameter( hStmt,
    1,

    SQL_PARAM_INPUT,

    SQL_C_CHAR,
    SQL_CHAR,
    0,
    0,

    LIKE_CLAUSE,

    sqlBufferLen,

    &sqlStrLen )))
    printf( "Error in SQLBindParameter()\n" );
    else if ( ! SQL_SUCCEEDED( SQLExecute( hStmt )))
    printf( "Error in SQLExecute()\n" );
    else if ( ! SQL_SUCCEEDED( SQLFetch( hStmt )))
    printf( "Error in SQLFetch()\n" );
    else if ( ! SQL_SUCCEEDED( SQLGetData( hStmt,
    1,
    SQL_C_LONG,
    &sqlValue,
    sizeof(
    sqlValue ),
    &sqlNull )))
    printf( "Error in SQLGetData()\n" );
    else
    printf( "sqlValue/sizeof( sqlValue )/sqlNull = <%
    ld>/<%ld>/<%ld>\n", sqlValue, sizeof( sqlValue ),
    sqlNull );
    }


    ================================

    I am using the latest SQL Server 8 with Visual C/C++ 6.00.

    Everything has the latest software patches including the
    DB and compilers.

    Regards,

    Angelo

    >-----Original Message-----
    >Could you post all the parameters for SQLBindParameter()

    method. I am
    >pretty confident that 'A%' is the correct syntax
    >
    >Pete
    >
    >Angelo wrote:
    >
    >>I'm trying to execute the following query within a

    Visual
    >>C++ program...
    >>
    >>SELECT LastName from Employees WHERE LastName LIKE ?
    >>
    >>In the C++ program, I use the SQLBindParameter() to
    >>associate to the ?. The SQLBindParameter() variable

    used
    >>contains 'A%' (without the single quote).
    >>
    >>This is a very simple statement, but constantly returns
    >>no data.
    >>
    >>I run this exact statement within a MS Access database
    >>connection, and it returns 4 records. The MS Access

    wild
    >>card is also 'A%'. I think there is a bug in the SQL
    >>Server ODBC, but I cannot confirm this.
    >>
    >>Using the SQL Trace doesn't tell me the translations
    >>being performed within the ODBC driver to confirm a bug.
    >>
    >>Help...please...
    >>
    >>Regards,
    >>
    >>Angelo
    >>
    >>

    >
    >--
    >
    >You don't pay to get spam, why pay to clean it?
    >Visit http://www.spammarshall.com to create an account

    for free
    >
    >
    >
    >


+ Reply to Thread