Article View: microsoft.public.vc.language
Article #108Re: SQL0007N The Character "%" following "[...] NOT LIKE 'WP-" IS NOT VALID. SQLSTATE=42601
From: Steve Kass
Date: Wed, 23 Oct 2002 23:10
Date: Wed, 23 Oct 2002 23:10
68 lines
3681 bytes
3681 bytes
It looks to me like the problem is that you have single quotes around the
second %s of the format string. They are correct around the first, since
you need to quote the part number in [VEND_PART_NO] = 'abc949',
but around the second, I think you end up quoting part of your WHERE
clause:
[VEND_PART_NO] = 'abc949' AND
'[VEND_PART_NO] NOT LIKE 'WP-%' AND [VEND_PART_NO] NOT
LIKE 'KS-%''
It's always an excellent idea to actually look at the query you
construct when you do anything like this - if the error is what I think,
you will catch it if you look at the query (and even perhaps try to run it
outside your program).
Steve Kass
Drew University
moniqueh wrote:
> Hi all,
>
> I am trying to query a database using SQL in my Visual C++ program
> code.
> In the WHERE clause, I want to exclude all the VEND_PART_NO starting
> with 'WP-' and 'KS-'. So, I used "%" character and "NOT LIKE" in my
> SQL statement. The following is my SQL codes and the error message I
> am getting:
>
> Error message:
>
> SQL0007N The Character "%" following "RT_NO] NOT LIKE 'WP-" IS NOT
> VALID. SQLSTATE=42601
>
> Visual C++ and SQL Codes:
>
> CString lpszSQLPN, templpszSQL;
> templpszSQL = "[VEND_PART_NO] NOT LIKE 'WP-%' AND [VEND_PART_NO] NOT
> LIKE 'KS-%'";
>
> lpszSQLPN.Format("SELECT DISTINCT [PART_NO] \
> FROM [CCL].[APPRVD_VEND_PART] \
> WHERE \
> (\
> [VEND_ID] = %d AND \
> [VEND_ID] != 722 AND \
> [VEND_ID] != 999 AND \
> [VEND_PART_NO] = '%s'AND \
> '%s' \
> ) \
> ORDER BY [PART_NO]",m_pSet->m_VEND_ID,m_pSet->m_VEND_PART_NO,
> templpszSQL);
>
> if( ( m_pSetPN->Open(CRecordset::forwardOnly,lpszSQLPN,CRecordset::readOnly)
> ) == 0)
> AfxMessageBox("Error opening Recordset!");
>
> I didn't include the templpszSQL statement directly in lpszSQLPN
> because the VC++ compiler seems to confuse the "%" character for SQL
> with the "%s" and "%d" which parameters are being passed into in a
> CString::Format statement.
>
> Please help....
>
> Thanks for any ideas in advance.
>
> Regards,
> Monique
Technical Details
Message-ID:
<3DB72C80.BF199E3A@drew.edu>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!arclight.uoregon.edu!wn13feed!wn11feed!worldnet.att.net!207.217.77.102!newsfeed2.earthlink.net!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!stamper.news.atl.earthlink.net!harp.news.atl.earthlink.net!not-for-mailReferences:
<a1f65222.0210231329.3b871aa4@posting.google.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10f47b,c707df194bcd0d5d X-Google-Attributes: gid10f47b,public X-Google-Thread: f7a51,c707df194bcd0d5d X-Google-Attributes: gidf7a51,public X-Google-Thread: f8b20,c707df194bcd0d5d X-Google-Attributes: gidf8b20,public X-Google-Thread: 103747,c707df194bcd0d5d X-Google-Attributes: gid103747,public X-Google-ArrivalTime: 2002-10-23 16:08:59 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!arclight.uoregon.edu!wn13feed!wn11feed!worldnet.att.net!207.217.77.102!newsfeed2.earthlink.net!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!stamper.news.atl.earthlink.net!harp.news.atl.earthlink.net!not-for-mail From: Steve Kass <skass@drew.edu> Newsgroups: microsoft.public.vc.language,microsoft.public.vc.database,comp.databases.ibm-db2,ibm.software.db2.udb.windows2000 Subject: Re: SQL0007N The Character "%" following "[...] NOT LIKE 'WP-" IS NOT VALID. SQLSTATE=42601 Date: Wed, 23 Oct 2002 19:10:56 -0400 Organization: MindSpring Enterprises Lines: 69 Message-ID: <3DB72C80.BF199E3A@drew.edu> References: <a1f65222.0210231329.3b871aa4@posting.google.com> NNTP-Posting-Host: 42.20.e7.19 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Server-Date: 23 Oct 2002 23:08:58 GMT X-Mailer: Mozilla 4.79 [en] (Windows NT 5.0; U) X-Accept-Language: en