Results 1 to 4 of 4

Thread: apostrophize in insert

  1. #1
    Join Date
    Jun 2005
    Posts
    2

    apostrophize in insert

    Hi

    I want to insert this kind of value

    insert into z3000 (a,b,c)
    values ('aaaa','i don't want','sdsd');

    how i can use the ' in my value?

    Thanks alex

  2. #2
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    create table z3000 (a varchar(10), b varchar(20), c varchar(20))
    set quoted_identifier off
    insert into z3000 (a,b,c) values ("'aaaa'","'i don't want'","'sdsd'")

  3. #3
    Join Date
    Jun 2005
    Posts
    2
    ok thank you, i will try it.

    but, if i wish to send a insert for a ntext field (fronm a memo field(foxpro)) and the data is a html page, what I need to use

    like

    create table z3000 (a ntext,numeric(4))
    && the equivalent of a memo field in &&foxpro

    insert into z3000 (a,b)
    values ("<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head><title>Database Journal Forums - Reply to Topic</title>
    <meta http-equiv="MSThemeCompatible" content="Yes">",'45676');

    ?

    Alex

  4. #4
    Join Date
    Feb 2003
    Posts
    1,048
    Another method that I prefer is to escape the single quote. You do this by doubling it.

    create table z3000 (a varchar(10), b varchar(20), c varchar(20))

    insert into z3000 (a,b,c)
    values ('aaaa','i don''t want','sdsd')


    Note that that's not a double quote, it's 2 single quotes.

    If you are building a sql string in code, simply use the replace() function to replace all single quotes with 2 single quotes.

    Working with the example above in ASP:

    Dim sValue2
    Dim sSQL

    sValue2 = "i don't want"
    sValue2 = Replace(sValue2, "'", "''")

    sSql = "insert into z3000 (a,b,c) values ('aaaa'," & sValue2 & ",'sdsd')"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •