Link to home
Start Free TrialLog in
Avatar of ambuli
ambuliFlag for United States of America

asked on

SQL handling single and double quotes

Hi there,
I have to insert and delete some data using names that may contain single or double quotes.


INSERT INTO Table (Name,Value) VALUES (' "nameString" ', ' "valueString" ');
DELETE FROM Table WHERE Name= "nameString";

When nameString has a single Quote like, a'mbuli, then I replace the single quote with two single quotes like (a''mbuli) and it works.

But, how can I handle a double quote for example, a"mbuli

Thank you.
SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Qlemo is correct for the explanation. so for your example, you should do this:
INSERT INTO Table (Name,Value) VALUES ( 'nameString' , 'valueString' );
DELETE FROM Table WHERE Name= 'nameString' ;

Open in new window


if the string value itself contains a single quote, like a'mbuli,  you can try:
INSERT INTO Table (Name,Value) VALUES ( 'nameString' , 'a''mbuli' );
DELETE FROM Table WHERE Value = 'a''mbuli' ;

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial