top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

How to handle “apostrophe in a string” problem in MS SQL Server Insert Command?

0 votes
125 views
How to handle “apostrophe in a string” problem in MS SQL Server Insert Command?
posted Mar 29, 2016 by Sathyasree

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

When creating SQL statements, string values are delimited using apostrophes. So what happens when there is an apostrophe in the data you are trying to insert.

INSERT INTO DevASPtable (phrases) VALUES ('DevASP’s articles')

“DevASP’s articles” here u see there is a apostrophe in the string now it generate an syntax error due to this it crash your software. So how can you handle this problem using a simple command.

To insert an apostrophe into the database using SQL you need to "double-up" the apostrophes. That is, put two apostrophes in the text where you want just one. For example, to insert the phrase " DevASP’’s” articles into a database, the SQL code looks like:

INSERT INTO DevASPtable (phrases) VALUES (' DevASP’s articles ')

Now here is a simple command in VB.Net with which you can resolve this problem:

Dim str as String=“DevASP’s articles”
str.Replace(”’”,”’’”)

Now your string change into double apostrophes sign string mean DevASP’s articles
Note: This does not insert two apostrophes into the database

answer Mar 29, 2016 by Shivaranjini
Similar Questions
+10 votes

I have 15-20 tables and i want to export the data from those tables to excel.

+2 votes

I'm trying to connect to a MS SQL Server Express 2005 using PDO for ODBC, but I need the DSN string. I tried with:

$dsn = 'odbc:DRIVER={SQL Server};HOSTNAME=CCTPV608SQLEXPRESS;DATABASE=db_ibripos';

but it doesn't work, please help.

+1 vote

I have a simple mapping that reads data from a SQL Server table with a column of type 'money'. The column is mapped to another table with the column of type decimal 19,4. (Informatica converts type money to type decimal 19,4.) When running the workflow, no rows are inserted into the target table, and no meaningful errors are produced. However the data is inserted correctly when the money column mapping is deleted.

Looking at the session log, it appears Informatica believes the rows were inserted correctly.

How can I correctly map the money column to a SQL server table.

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...