Re: SQL Syntax for a single quote in a string.



"lsg" <sgling07@xxxxxxxxx> wrote in
news:44ebff25$1@xxxxxxxxxxxxxxxxxxxxxx:


Hi,
I don't know how to write a syntax in SQL if there is a quote mark in
a string. Example :
Str := 'Sawal Afa'at'; <--- a'a
...
Add('update tbl set name='''+str+''''); ---> i used 3 single
quote on both sides. .... etc
this statement will give me error.
Can someone assist me how to solve this problem? Thanks in advance

Regards,
lsg



Try this:

Str := 'Sawal Afa''at'

But the suggested method is to use a parameter. For example:

var
cmd: TADOCommand;
begin
cmd := TADOCommand.Create(aConnection);
try
cmd.CommandText := 'update tbl set name=:1';
with cmd.Parameters.AddParameter do
begin
DataType := ftString;
Direction := pdInput;
Value := 'Sawal Afa''at';
end;
cmd.Execute;
finally
cmd.Free;
end;
end;

George
.



Relevant Pages

  • SQL Syntax for a single quote in a string.
    ... I don't know how to write a syntax in SQL if there is a quote mark in a string. ...
    (borland.public.delphi.database.ado)
  • Re: The usage of "eval"
    ... > Assuming the value of a variable CMD is: ... > To run it as a command, ... > each quote mark with an \ to escape it. ...
    (comp.unix.shell)
  • Re: simple but weird string concatenation
    ... I know string concatenation is not a good approach. ... I build a sql string, but sometime what I got missing the last part -- ")". ... I can not use db cmd parapeter, seems sqlite does not support it. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: "Corrupted" query
    ... That looks complicated, but in order to get one quote mark inside a string, you ... with seven fields the query once it is reformatted by Access gets to ... >> source for the report. ...
    (microsoft.public.access.queries)
  • Re: "Corrupted" query
    ... passing it a field name that it does not recognize. ... It might be clearer if you use the Chr function - Chris a quote mark if I ... Play with those and see if you can get the expected string. ... >> Msgbox strWhere ...
    (microsoft.public.access.queries)