Visual C++ 7.0DBAWindows 2000Visual C++ 6.0Windows XPMFCIntermediateDevVisual StudioSQL ServerSQLWindowsC++
Remove comment in SQL






2.72/5 (23 votes)
Feb 13, 2003

68348

464
Remove comment in SQL to make it easy to execute with MS Access.
Introduction
Your can write SQL which reads good, like this:
-- What the sql (et. stored procedure )writen for
-- and/or how to use it
/* Or block comment like this
What the sql (et. stored procedure )writen for
and/or how to use it
*/
create table tablename (
fieldname text(255), -- comment for field
content text(255));
Comments in SQL statements sent through ADO will sometimes error out in ADO when ADO tries to parse it. By stripping out the comments, you have both documented SQL code and you don't get any errors when you try to use the commented code within your ADO application. Then use these SQL saved in files directly!
How to use it?
Declare the function in any .h file of your project:
int ClearSQLComment(LPCTSTR lpSQL,CString &rString);
and use it:
CString strText,strSQL; //Read all text from file to a CString object ,write it yourselft LoadTextFromFile(lpFileName,&strText); ClearSQLComment(strText,strSQL); //...Execute SQL Connect.Execute(strSQL,&affected,adCmdText);