🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: microsoft.public.vc.language
Article #107

SQL0007N The Character "%" following "[...] NOT LIKE 'WP-" IS NOT VALID. SQLSTATE=42601

#107
From: moniqueh
Date: Wed, 23 Oct 2002 21:29
50 lines
2539 bytes
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: <a1f65222.0210231329.3b871aa4@posting.google.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10f47b,c707df194bcd0d5d,start
X-Google-Attributes: gid10f47b,public
X-Google-Thread: 103747,c707df194bcd0d5d,start
X-Google-Attributes: gid103747,public
X-Google-Thread: f8b20,c707df194bcd0d5d,start
X-Google-Attributes: gidf8b20,public
X-Google-Thread: f7a51,c707df194bcd0d5d,start
X-Google-Attributes: gidf7a51,public
X-Google-ArrivalTime: 2002-10-23 14:29:59 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mail
From: moniqueho@hotmail.com (moniqueh)
Newsgroups: microsoft.public.vc.language,microsoft.public.vc.database,comp.databases.ibm-db2,ibm.software.db2.udb.windows2000
Subject: SQL0007N The Character "%" following "[...] NOT LIKE 'WP-" IS NOT VALID.  SQLSTATE=42601
Date: 23 Oct 2002 14:29:59 -0700
Organization: http://groups.google.com/
Lines: 50
Message-ID: <a1f65222.0210231329.3b871aa4@posting.google.com>
NNTP-Posting-Host: 205.233.28.38
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: posting.google.com 1035408599 20456 127.0.0.1 (23 Oct 2002 21:29:59 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: 23 Oct 2002 21:29:59 GMT