Link to home
Start Free TrialLog in
Avatar of dealclick
dealclick

asked on

Update SQL query


I'm using Delphi 5 with MS SQL and am trying to execute a update SQL query.  Mostly I have been updating integer fields which has been no problem, but now I want to update a string field, which is causing me problems because of the single quotes needed in the SQL.

EG

AdoCommand.CommandText := 'update customer set CustomerType = 'text' where rec = 99;

Obvisouly the problem here is that the 'text' must be in single quotes (or somthing similar) but also the SQL stmt must be in single quotes as well  (or something similar)

However I don't know what the something similar must be.

Simple I know, but I'm really stumped as to that I should use.

Thaniks
Avatar of Darth_helge
Darth_helge

AdoCommand.CommandText := 'update customer set CustomerType = ''text'' where rec = 99';

two single quotes in a row before and after the text-string.
this should do the trick :=)

if the string is stored in a variable s do this:

AdoCommand.CommandText := 'update customer set CustomerType = ''' + s + ''' where rec = 99';
ASKER CERTIFIED SOLUTION
Avatar of kretzschmar
kretzschmar
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
but better would be to use a parameter like

AdoCommand.CommandText := 'update customer set CustomerType = :1 where rec = 99';
AdoCommand.Parameters[0].AsString := 'text';


not tested

meikl ;-)

Avatar of dealclick

ASKER


Thanks meikl, I've used the first solution cause it matches my simple mind, but accept that the param would maybe be a better way to go.

;-)
glad you got it work :-))

for Darth_helge,

i posted a q for you,
because your suggestion are also correct

meikl ;-)