Home > Archive > FoxPro Help and Support > July 2005 > how to insert string into SQL server table with single quote









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author how to insert string into SQL server table with single quote
Sunny

2005-07-18, 1:24 pm

Hi I am using VFP 9.0 and SQL server 2003. I need to insert O'Neal as
lastname into my table located on sql server throgh SQLEXEC command. Since
it has single quote I am getting error. how can I do it?

Thanks.


jack

2005-07-18, 1:24 pm

Would a variable substitution work?

i.e.

m.lname = "O'neill"
mcmd = 'Insert into tblXX (fldLastName) values (m.lname)'


Jack

"Sunny" <sunny_1178@hotmail.com> wrote in message
news:ey7JpV8iFHA.3256@TK2MSFTNGP12.phx.gbl...
> Hi I am using VFP 9.0 and SQL server 2003. I need to insert O'Neal as
> lastname into my table located on sql server throgh SQLEXEC command. Since
> it has single quote I am getting error. how can I do it?
>
> Thanks.
>
>



jndb72

2005-07-18, 1:24 pm



Sunny wrote:
> Hi I am using VFP 9.0 and SQL server 2003. I need to insert O'Neal as
> lastname into my table located on sql server throgh SQLEXEC command. Since
> it has single quote I am getting error. how can I do it?
>
> Thanks.


Hi,

One way is to store the value to a variable.

LOCAL lcSql, lnRetVal
lcSql = "O'Neil"
lnRetVal = SQLEXEC(lnConnection
Handle, "INSERT INTO YourTable
(YourField) VALUES (?lcSql)")

hth

Olaf Doschke

2005-07-18, 1:24 pm

> I need to insert O'Neal
> on sql server


SQL server takes two single quotes as one:

O''Neil should work.


either

insert into mytable (name) values ('O''Neil')
or
insert into mytable (name) values ("O''Neil")

unsure about :
insert into mytable (name) values ("O'Neil")

Bye, Olaf.


Sunny

2005-07-18, 8:24 pm

Thanks everybody for quick response.
"Sunny" <sunny_1178@hotmail.com> wrote in message
news:ey7JpV8iFHA.3256@TK2MSFTNGP12.phx.gbl...
> Hi I am using VFP 9.0 and SQL server 2003. I need to insert O'Neal as
> lastname into my table located on sql server throgh SQLEXEC command. Since
> it has single quote I am getting error. how can I do it?
>
> Thanks.
>
>



Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com