Solved

Inserting a value regardless what it is

Posted on 2009-05-15
6
170 Views
Last Modified: 2012-05-07
Is there anyway of inserting a value into SQL regardless what it is?

I have this value that I want to insert; L'INIZIO SET LUNCH but the ' is offending and SQL will not insert it saying: Incorrect syntax near 'INIZO'. Unclosed quotation mark after the character string ');'.
0
Comment
Question by:richard_gar
6 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 24397606
replace that Single  quote with two single quotes

insert into urTable
SELECT '  L''INIZIO SET LUNCH  '
0
 
LVL 8

Expert Comment

by:SNilsson
ID: 24397959
If you want to do this once adding a single quote will do, if you want to automate this you should doubble up the single quotes in a insert/update trigger or in a SP if thats what your using.

If so you can use the sql command Replace to change ' to ''
0
 
LVL 13

Expert Comment

by:St3veMax
ID: 24398930
try:

INSERT INTO dbo.tbl_MyTable ('Col1') VALUES ('L''INIZIO SET LUNCH')

HTH
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24399448
of course, the '' instead of the ' will solve the issue in sql.
however, what programming language do you use? most (all) support bind parameters, which handle this issue transparently.
0
 

Author Comment

by:richard_gar
ID: 24399642
vb.net
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 24399732
see this tutorial:
http://www.dotnetspider.com/resources/90-Using-SqlParameter-Class.aspx

as you see, just a matter of defining the parameter, and you won't need to care about neither quotes, and for dates about the format etc.
just pass the value into the parameter, and you are done.
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Server Degrading on Write 13 67
Not selecting duplicate data 6 53
Analysis of table use 7 47
Help with stripping out character in SQL LEFT/RIGHT/REPLACE 2 45
Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question