473,748 Members | 2,574 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

The dreaded apostrophe & sql

You all helped me with function keys last week. Thanks so much; your advice
was right on.

My question now - does anyone have a function that I can use to test my sql
statements for the apostrophe and quote and do a search/replace type thing.
I'd like something to put in my basFunctions module instead of replacing
every time I do a sql command in my program code. Thanks!

Jul 17 '05 #1
4 10440
Changing apostophe and quote into what?

Let's say change all a's into b's:

sql$=replace(sq l$,"a","b")

Cheers
Arjen
"Meyer1228" <ka***@ecsnj.co m> schreef in bericht
news:HQ******** **********@nwrd dc02.gnilink.ne t...
You all helped me with function keys last week. Thanks so much; your advice was right on.

My question now - does anyone have a function that I can use to test my sql statements for the apostrophe and quote and do a search/replace type thing. I'd like something to put in my basFunctions module instead of replacing
every time I do a sql command in my program code. Thanks!

Jul 17 '05 #2
Try this:

Public Function FixImbeddedQuot es(strInput As String, Optional strQuoteChar
As String = "'") As String
On Error GoTo ErrorHandler
Dim lsWork As String

FixImbeddedQuot es = strInput

lsWork = strInput
If Len(lsWork) > 0 Then
Do While InStr(lsWork, strQuoteChar) > 0
lsWork = Replace(lsWork, strQuoteChar, Chr$(&HFF))
Loop

Do While InStr(lsWork, Chr$(&HFF)) > 0
lsWork = Replace(lsWork, Chr$(&HFF), strQuoteChar &
strQuoteChar)
Loop

End If

FixImbeddedQuot es = lsWork

FixImbeddedQuot es_Done:
On Error Resume Next
Exit Function

ErrorHandler:
Dim lngErrNum As Long: Dim strErrDesc As String: lngErrNum = Err.Number:
strErrDesc = Err.Description
MsgBox "Err#" & Err.Number & vbCrLf & vbCrLf & "Desc: " &
Err.Description , vbExclamation, "FixImbeddedQuo tes"
Resume FixImbeddedQuot es_Done
Resume ' for debug
End Function

Jul 17 '05 #3
My standard "MakeSQLStr ing" function has been the same for many years...
(although recently upgraded to .NET and can probably be improved on... lol)

Public Function MakeSQLString(p StringToBeSQLd As String) As String
' Define apostrophe from good ol' ASCII number
Dim vApostrophe As Char = Convert.ToChar( 39)
' Double up any apostrophes
Dim vOutput As String = pStringToBeSQLd .Replace(vApost rophe, vApostrophe &
vApostrophe)
' Add apostrophes to each end of the string
Return vApostrophe & vOutput & vApostrophe
End Function

Usage;

Dim vName As String
Dim vSQL As String
vName = "Grim"
vSQL = "SELECT * FROM myTable WHERE myWhereClause=" & MakeSQLString(v Name) &
";"
..... <query DB>
_______________ _______________ ___
The Grim Reaper

"Meyer1228" <ka***@ecsnj.co m> wrote in message
news:HQ******** **********@nwrd dc02.gnilink.ne t...
You all helped me with function keys last week. Thanks so much; your advice was right on.

My question now - does anyone have a function that I can use to test my sql statements for the apostrophe and quote and do a search/replace type thing. I'd like something to put in my basFunctions module instead of replacing
every time I do a sql command in my program code. Thanks!

Jul 17 '05 #4
My apologies!!! Too busy watching TV, I didn't realise I was in the VB
group, not the .NET one I'm usually in!!
Here's a "translation".. .

Public Function MakeSQLString(p StringToBeSQLd As String) As String
' Define apostrophe from good ol' ASCII number
Dim vApostrophe As String = Chr(39)
' Double up any apostrophes
Dim vOutput As String = Replace(pString ToBeSQLd, vApostrophe, vApostrophe
& vApostrophe)
' Add apostrophes to each end of the string
MakeSQLString = vApostrophe & vOutput & vApostrophe
End Function

Usage;

Dim vName As String
Dim vSQL As String
vName = "Grim"
vSQL = "SELECT * FROM myTable WHERE myWhereClause=" & MakeSQLString(v Name) &
";"
..... <query DB>
_______________ _______________ ___
The Grim Reaper
"The Grim Reaper" <gr*********@bt openworld.com> wrote in message
news:ca******** **@titan.btinte rnet.com...
My standard "MakeSQLStr ing" function has been the same for many years...
(although recently upgraded to .NET and can probably be improved on... lol)
Public Function MakeSQLString(p StringToBeSQLd As String) As String
' Define apostrophe from good ol' ASCII number
Dim vApostrophe As Char = Convert.ToChar( 39)
' Double up any apostrophes
Dim vOutput As String = pStringToBeSQLd .Replace(vApost rophe, vApostrophe & vApostrophe)
' Add apostrophes to each end of the string
Return vApostrophe & vOutput & vApostrophe
End Function

Usage;

Dim vName As String
Dim vSQL As String
vName = "Grim"
vSQL = "SELECT * FROM myTable WHERE myWhereClause=" & MakeSQLString(v Name) & ";"
.... <query DB>
_______________ _______________ ___
The Grim Reaper

"Meyer1228" <ka***@ecsnj.co m> wrote in message
news:HQ******** **********@nwrd dc02.gnilink.ne t...
You all helped me with function keys last week. Thanks so much; your

advice
was right on.

My question now - does anyone have a function that I can use to test my

sql
statements for the apostrophe and quote and do a search/replace type

thing.
I'd like something to put in my basFunctions module instead of replacing
every time I do a sql command in my program code. Thanks!


Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
7982
by: Michael Sterling | last post by:
i'm using delphi 7 and have a query in which i'm trying to find names that have an apostrophe in them, i.e. "o'mally". my problem is that when i write my select statement i can't get the quotes right. i get all types of errors no matter what i try. i get "missing right quote", "invalid token" etc. i've tried using QuotedStr and nothing works. here is my current attempt in which i get an "invalid use of keyword. token: n'%'" sSQL :=...
2
1649
by: InvisibleMan | last post by:
Thank in advance for your help... I have the following javascript: document.write(' <a class="whitenav" href="javascript:window.external.AddFavorite ('http://www.mydomain.com','Welcome to MyDomain.com')">Bookmark Site</a> |'); where the problem arises with the apostrophe's in:
15
7986
by: soup_or_power | last post by:
Hello All: I'm having a whale of a problem with the following code. When the words beginning with sugg contain an escaped single-quote (\' ==> back-slash followed by quote) the script causes an error. How can I preserve the single quote. Please review the code below and let me know. Many thanks! function clicker( but_id, sugg0, sugg1, sugg2, sugg3, sugg4, sugg5, copy_type, p1) {
1
5376
by: congngo | last post by:
Hi all Every time I export a table into an excel spreadsheet. It has a leading apostrophe on every cells. This drive me nut. I have to do a work around by export table into a txt file than import in excel to get rid of the apostrophe. It has been happen about two months now before it didn't do that. It is only happen when I have text data type in the table. If I change to number data type then the problem go away but most of my...
1
300
by: spacehopper_man | last post by:
hi - I am having "apostrophe in sql" problems ;) I am executing a stored procedure on SQL Server - and passing in a string parameter. the string has a single apostrophe in it. the call is failing with an "Incorrect syntax" message.
1
4023
by: Rose | last post by:
Hi all, I'm trying to create a clickable link, but the pesky apostrophe is preventing the link from getting displayed properly. I'm displaying the contents of a folder (with contains the apostrophe), with the filename as a clickable link. The files show up properly, but the link location cuts off at the apostrophe. Here's a code snippet (fi is an instance of FileInfo):
2
12332
by: Tom | last post by:
Hi, I have some kind of problems with an apostrophe character ('). I would like to select from DataTable DataRow containing value horses' (with an apostrophe on the end). But when I do it in an obvious way, like this: DataTable dt = new DataTable(); DataColumn id = new DataColumn("ID", Type.GetType("System.Int32"));
9
3596
by: Thomas 'PointedEars' Lahn | last post by:
Jukka K. Korpela wrote: IBTD. For example, in English it is customary (and AIUI expected) to use the character that ’ represents should be used to delimit a quotation within direct speech (which itself should be delimited by “ and ”. (I gathered that from reading several English books.) I think you would agree that it would make especially English text with quotations in direct speech (say, in a novel where one person tells another...
4
2274
by: Razzbar | last post by:
I'm working on a bookmarklet that grabs information from a page and submits it to a server. Yet another social bookmarking application. I'm having trouble with page titles that include an apostrophe. I'm using encodeURIComponent() around the page title, and again around the URL. Apparently the browser is inserting a backslash before any apostrophe. I can see that when I write the $_GET data to a file in PHP on the server. When the GET...
0
8996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9386
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9333
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.