devxlogo

Passing Text Fields

Question:
I need to pass large fields of text. Problem is, some of the text has single quotes in it ( ‘ ). How do I pass these text fields to SQL without getting an error?

For example:

sqlText = "EXEC sp_NewEntry '" &  thisText & "', '" & thatText & "', '" & moreText & "', '"

I need to wrap all of the text in single quotes to SQL, but if any of the text contains single quotes, it burps an error. What’s the syntax to pass the text correctly?

Answer:
I thought I saw a solution for this while I was in training, where they used square brackets and “`” as a delimiter, which was a new one on me. I’m not certain, but I think the thing to do is to use double single quotes ('') to mark the included quote mark.

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  Five Early Architecture Decisions That Quietly Get Expensive

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.