Solved

Inserting a value regardless what it is

Posted on 2009-05-15
6
168 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
Comment Utility
replace that Single  quote with two single quotes

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

Expert Comment

by:SNilsson
Comment Utility
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
Comment Utility
try:

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

HTH
0
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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
Comment Utility
vb.net
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now