Click here to Skip to main content
15,883,883 members
Articles / Desktop Programming / MFC
Article

Remove comment in SQL

Rate me:
Please Sign up or sign in to vote.
2.72/5 (23 votes)
12 Feb 2003 67.8K   458   17   5
Remove comment in SQL to make it easy to execute with MS Access.

Introduction

Your can write SQL which reads good, like this:

SQL
-- 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);

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5 Pin
Shiv Rathod28-Feb-21 5:27
Shiv Rathod28-Feb-21 5:27 
Generalthe best way to "remove" SQL comment Pin
Anonymous13-Feb-03 7:58
Anonymous13-Feb-03 7:58 
GeneralRe: the best way to "remove" SQL comment Pin
colison13-Feb-03 13:50
colison13-Feb-03 13:50 
GeneralRe: the best way to "remove" SQL comment Pin
Anonymous20-Feb-03 7:52
Anonymous20-Feb-03 7:52 
GeneralRe: the best way to "remove" SQL comment Pin
Terry Denham14-Feb-03 3:27
Terry Denham14-Feb-03 3:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.