473,320 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

SET QUOTED_IDENTIFIER OFF

Hello!
How bad is it to use SET QUOTED_IDENTIFIER OFF before an INSERT and
then switch it ON straight afterwards. So I can insert strings like
O'Neil etc.
It's my only design option at the moment. Everything works fine and as
far as I can see, it's only set to OFF for the current
connection/session so no other users will run into problems at the
same time if they need it ON, right?

Thanks Martin
Jul 20 '05 #1
4 9985
On 14 Jan 2004 20:56:32 -0800, th************@hotmail.com (Martin) wrote:
Hello!
How bad is it to use SET QUOTED_IDENTIFIER OFF before an INSERT and
then switch it ON straight afterwards. So I can insert strings like
O'Neil etc.
It's my only design option at the moment. Everything works fine and as
far as I can see, it's only set to OFF for the current
connection/session so no other users will run into problems at the
same time if they need it ON, right?

Thanks Martin


Why is this an issue?

If you're dealing with a string literal in a stored procedure or query
analyzer, you can just type a double-apostrophe to get a single apostrophe in
the string. If you're passing data from the client, you should use
parameters, and let ADO or ODBC handle passing the data properly to SQL
Server. The only other case I can think of is when you're building dynamic
SQL, and then you can use the replace function to convert ' into '' so it will
evaluate correctly.
Jul 20 '05 #2
Regardless of the literal character enclosure you use, you'll have problems
when you build SQL statements with character literals that include the
enclosure character. These need to be escaped with 2 consecutive enclosure
characters. For example:

SET QUOTED_IDENTIFIER OFF
SELECT "This is a "double-quoted" string"
--Incorrect syntax near the keyword 'double'.
GO
SELECT "This is a ""double-quoted"" string"
--works
GO

SET QUOTED_IDENTIFIER ON
SELECT 'This is a 'single-quoted' string'
--Line 2: Incorrect syntax near '-'.
GO
SELECT 'This is a ''single-quoted'' string'
--works
GO

QUOTED_IDENTIFIER ON is preferred because this is the ANSI standard. In the
case of SQL Server, this is one of the SET options that must be on in order
to use indexes on computed columns and views effectively so I suggest you
standardize on QUOTED_IDENTIFIER ON. You can make your application code
cleaner if you use parameters so that the API to takes care of this for you.

--
Hope this helps.

Dan Guzman
SQL Server MVP

"Martin" <th************@hotmail.com> wrote in message
news:72**************************@posting.google.c om...
Hello!
How bad is it to use SET QUOTED_IDENTIFIER OFF before an INSERT and
then switch it ON straight afterwards. So I can insert strings like
O'Neil etc.
It's my only design option at the moment. Everything works fine and as
far as I can see, it's only set to OFF for the current
connection/session so no other users will run into problems at the
same time if they need it ON, right?

Thanks Martin

Jul 20 '05 #3
Martin (th************@hotmail.com) writes:
How bad is it to use SET QUOTED_IDENTIFIER OFF before an INSERT and
then switch it ON straight afterwards. So I can insert strings like
O'Neil etc.
It's my only design option at the moment. Everything works fine and as
far as I can see, it's only set to OFF for the current
connection/session so no other users will run into problems at the
same time if they need it ON, right?


In addition to the comments from Steve and Dan, note that this will not
work in a stored procedure, trigger or user-defined function because in
this case the setting that was in force when the procedure created will
apply, and the statement in the procedure will have no effect.

I have however, occasionally written dynamic SQL which starts with
SET QUOTED_IDENTIFIER, which saves me from the hassle of nested quotes.
There are however other alternatives for this situation, like using
the built-in funcion quotename().
--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #4
Thanks guys for answering my question.
I've spent some time on Erland's site and came to the conclusion that
I better follow a wise man's advice!

Have a nice day!

Erland Sommarskog <so****@algonet.se> wrote in message news:<Xn*********************@127.0.0.1>...
Martin (th************@hotmail.com) writes:
How bad is it to use SET QUOTED_IDENTIFIER OFF before an INSERT and
then switch it ON straight afterwards. So I can insert strings like
O'Neil etc.
It's my only design option at the moment. Everything works fine and as
far as I can see, it's only set to OFF for the current
connection/session so no other users will run into problems at the
same time if they need it ON, right?


In addition to the comments from Steve and Dan, note that this will not
work in a stored procedure, trigger or user-defined function because in
this case the setting that was in force when the procedure created will
apply, and the statement in the procedure will have no effect.

I have however, occasionally written dynamic SQL which starts with
SET QUOTED_IDENTIFIER, which saves me from the hassle of nested quotes.
There are however other alternatives for this situation, like using
the built-in funcion quotename().

Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Matt Rink | last post by:
Getting an "incorrect settings: 'ANSI_NULLS., QUOTED_IDENTIFIER'." error after creating a view. We wanted a composite unique constraint that ignored nulls, so we set up a view using the...
7
by: Bercin Ates via SQLMonster.com | last post by:
I?m getting an error when I execute a stored procedure which is try to insert a row to a table. The error is: Server: Msg 1934, Level 16, State 1, Procedure SRV_SP_IS_EMRI_SATIRI_EKLE, Line 32...
10
by: Adis | last post by:
Asp.Net Visual Studio 2003 SQL Server. Hi, Obtaining Data Based Upon Multiple Selections From a ListBox... I have database in Sqlserver and ListBox (Multiple Selection Mode) in my Visual...
4
by: John | last post by:
I have a very strange problem, it only happen to one SQL Server, other SQL Server seems to be fine I got the following error when trying to run a sp against one of the SQL Server: SELECT...
2
by: Ed Murphy | last post by:
Our client's application software requires all stored procedures to have quoted_identifier set a certain way. I've tripped over this a few times and promptly fixed it, but this morning, I had to...
3
by: Patrick.O.Ige | last post by:
Hi guys, Is there any free stuff to generate DAL code out there? Thanks in advance
6
by: ilo | last post by:
When I want to delete a data from a table that this tabl has a trigger and this trigger reached another tables to delete the data in cursor I have this messeage: DELETE failed because the...
3
by: Shestine | last post by:
I am trying to add a column to a current table, with data in it. I am only learning, and i have no idea how to change this to make it work. Here is the script I have right now it, but what it does is...
1
by: Ted | last post by:
does anyone know how to keep QA from adding the lines setting these two options on and off along with blank lines at the beginning and end of every object you edit? i have searched quite a bit on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.