Results 1 to 10 of 10

Thread: Insert apostrophe into SQL server

  1. #1

    Thread Starter
    Hyperactive Member maxl's Avatar
    Join Date
    Jan 2002
    Location
    Montréal
    Posts
    384

    Insert apostrophe into SQL server

    How do I insert an apostrophe into my database
    ex:
    Code:
    INSERT INTO BLAH(BlaBla) VALUES('Boîte d'engrenage')
    this will cause an error because of the quote inside the quotes
    COBOL sa suce !!!

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Don't use SQL. Use VB's .AddNew/.Update

    VB doesn't care about apostropes at all.

  3. #3

    Thread Starter
    Hyperactive Member maxl's Avatar
    Join Date
    Jan 2002
    Location
    Montréal
    Posts
    384
    Ok but if I use the addnew would the "SELECT @@Identity" work to get the PK of the record just inserted
    COBOL sa suce !!!

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VB's method requires using a pre-built recordset. I just generally do a SELECT * and use that.

  5. #5

    Thread Starter
    Hyperactive Member maxl's Avatar
    Join Date
    Jan 2002
    Location
    Montréal
    Posts
    384
    Yeah i forgot that I dont' need the select @@identity because I have a recordset so has soon has i update i can have access to the pk.
    COBOL sa suce !!!

  6. #6

    Thread Starter
    Hyperactive Member maxl's Avatar
    Join Date
    Jan 2002
    Location
    Montréal
    Posts
    384
    I was thinking, isn't it less effective to open a recordset just for inserting a row?
    COBOL sa suce !!!

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Originally posted by maxl
    I was thinking, isn't it less effective to open a recordset just for inserting a row?
    I won't argue with that, but, in my opinion, it beats the hell out of dancing around the SQL barn over inserting something with an apostrophe.

    Effective, or ineffective, for me is not even a remote concern. It is the easiest.

  8. #8
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    This is MS SQL Server?

    Write a Stored Procedure to do the Insert and use the ADO Command object to execute it - safer and faster.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    JoshT makes a good point. Actually, I do have a stored procedure that does this for me when I do inserts into Oracle.

    I made the assumption (perhaps incorrectly) that maxl was talking about an Access database.

  10. #10

    Thread Starter
    Hyperactive Member maxl's Avatar
    Join Date
    Jan 2002
    Location
    Montréal
    Posts
    384
    I am actually using SQL Server 2000 but I know nothing about stored procedure and by the way i found out how to insert an apostrophe you just double it ex:
    Code:
    Boîte d'engrenage
    becomes
    Code:
    Boîte d''engrenage
    COBOL sa suce !!!

Posting Permissions

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



Click Here to Expand Forum to Full Width