Advertisement

06.14.2004 at 06:59AM PDT, ID: 21024633
[x]
Attachment Details

Replace Single Quotes in SQL statement

Asked by probelaw in Active Server Pages (ASP)

Tags: replace, quote, single, sql

I'm trying to execute an SQL statement in a loop that contains some strings which have single quotes ( ' ) in the text of the string.  I've set the SQL statement itself as a string so then I can replace double quotes with 2 double quotes and tried to do the same for single quotes but it still throws an error.

SQLString = "INSERT INTO dbo.CSF_Reports (CorpName, ReportType, ReportDate, FileNumber, OldCode)  VALUES ('" & (rsOldSource.Fields.Item("Corporation_Name").Value) & "','" & (rsOldSource.Fields.Item("Report_Type_ID").Value) & "','" & (rsOldSource.Fields.Item("Report_Date").Value) & "','" & (rsOldSource.Fields.Item("File_Number").Value) & "'," & (rsOldSource.Fields.Item("Report_ID").Value) & ")"
SQLString = replace(SQLString, """", """""")
SQLString = replace(SQLString, "''", "''''")

The error occurs when it gets to a record with Corporation_Name of something liKe: Bob's Furniture
Start Free Trial
[+][-]06.14.2004 at 07:03AM PDT, ID: 11306480

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]06.14.2004 at 07:37AM PDT, ID: 11306860

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]06.14.2004 at 07:56AM PDT, ID: 11307049

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.14.2004 at 08:25AM PDT, ID: 11307393

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.14.2004 at 08:30AM PDT, ID: 11307453

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.14.2004 at 08:34AM PDT, ID: 11307493

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Active Server Pages (ASP)
Tags: replace, quote, single, sql
Sign Up Now!
Solution Provided By: vnvk
Participating Experts: 4
Solution Grade: A
 
 
[+][-]06.14.2004 at 01:05PM PDT, ID: 11310000

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.02.2004 at 04:08PM PDT, ID: 11699231

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32