|
 |
asp_discuss thread: Apostrophies in Strings
Message #1 by "Dave Landolin" <dave.landolin@o...> on Wed, 21 Aug 2002 21:31:33
|
|
When the following code is executed it fails on syntax because of the
apostrophy in the customer's name:
sql1 = "select distinct invoice_id, Invoice_Date, Item_Id, "
sql1 = sql1 + "Item_Name, Dollars "
sql1 = sql1 + "from ds_detail "
sql1 = sql1 + "where Customer_name = 'DAVE'S PAWN SHOP'"
How can I get around this?
I'm sure it's simple but it's making me nuts.
Thanks,
DL
Message #2 by Teng Fong SEAK <tfseak@f...> on Thu, 22 Aug 2002 09:40:12 +0200
|
|
If this string is to be used as an HTML string, change the apostrophe
to
' .
If it's JavaScript string, change it to \x27 .
I suppose you would soon encounter a similar problem with quote (").
In
that case, convert it to " (or ") for HTML string, or \x22
for
JavaScript string.
Good luck,
Fong
> -----Original Message-----
> From: Dave Landolin [mailto:dave.landolin@o...]
> Sent: mercredi 21 ao=FBt 2002 23:32
> To: asp_discuss
> Subject: [asp_discuss] Apostrophies in Strings
>
>
> When the following code is executed it fails on syntax because of the
> apostrophy in the customer's name:
> sql1 =3D "select distinct invoice_id, Invoice_Date, Item_Id, "
> sql1 =3D sql1 + "Item_Name, Dollars "
> sql1 =3D sql1 + "from ds_detail "
> sql1 =3D sql1 + "where Customer_name =3D 'DAVE'S PAWN SHOP'"
>
> How can I get around this?
> I'm sure it's simple but it's making me nuts.
>
> Thanks,
> DL
>
Message #3 by awrigley@y... on Thu, 22 Aug 2002 15:32:13
|
|
What language are you using?
Look in the help for the language under escape characters, escape
sequences, apostrophe escape sequence, etc.
This is a traditional problem that is solved using an alternative
character to enclose strings.
For example, in Access VBA, you would use "" (double double quotes)
instead of '(single quotes)
Ie, if you were hardcoding a variable you would write:
badstring = "select * from myTable where surname = 'D'Arcy';"
goodstring = "select * from myTable where surname = ""D'Arcy"";"
If you are refering to a variable then write:
Dim strName as String
badstring = "select * from myTable where surname = '" & strName& "';"
goodstring = "select * from myTable where surname = """ & strName & """;"
In both cases, badstring will work UNLESS you hit a name with an
apostrophe in it, but goodstring will always work.
Sorry the language divide, but is not clear which one you are using...
The best advice is to learn your way around the help for the language you
are using...
Regards
Andrew
Message #4 by "Dave Landolin" <dave.landolin@o...> on Thu, 22 Aug 2002 18:53:51
|
|
Thanks for your help Andrew.
The languages are Transact SQL and VBScript.
I solved the problem by:
namevar = replace(custname,"'","''")
and the sql:
select * from table where customer_name = '" & namevar & "'
Thanks Again,
DL
Message #5 by silly <xingyunpeng@s...> on Thu, 29 Aug 2002 19:51:41 +0800
|
|
Dave Landolin=A3=AC
There is some wrong with your sql1. To resolve this
problem,
you can set the value, "select distinct invoice_id,
Invoice_Date,
Item_Id, Item_Name, Dollars from ds_detail where Customer_name =3D
'DAVE''S PAWN SHOP'", to your sql1. That is, please replace the
single quotation mark which is after DAVE with two single
quotation
marks. That's ok.
Yunpeng Xing
xingyunpeng@s...
|
|
 |