Solved

Inserting a value regardless what it is

Posted on 2009-05-15
6
172 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

 
LVL 143

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 143

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
passing parameter in sql procedure 9 68
How can I get this column in my query? 2 56
Find results from sql within a time span 11 55
SQL- GROUP BY 4 23
Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 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