Bienvenido al sitio de software libre de CUTE, editor de bases de datos para MS Access y SQL Server. Este proyecto necesita reanimación desde Marzo de 2013.

 

Se puede realizar mediante donaciones, patrocinio o ayuda en la instalación.

donate sponsor aided installation
 

O puedes ayudar escribiendo nuevas traducciones, un artículo en la wikipedia acerca del programa, comentarios en foros o blogs, añadir código o documentación, etc... En cualquier caso gracias.

Single and double quotes in SQL Server

Sometimes, when executing a query like this:

SELECT * FROM Orders WHERE OrderDate = "01-01-98"

...things are getting wrong in SQL Server. Seems it's trying to get the specified value as a column name, and produces a syntax error. This query instead can be used as a workaround:

SET QUOTED_IDENTIFIER OFF
SELECT * FROM Orders WHERE OrderDate = "01-01-98"

SQL Server documentation says that double quote identifiers are valid only if QUOTED_IDENTIFIER is set to ON, which is the default on OLE DB provider and ODBC driver based connections. So when it is ON everything inside quotes is interpreted as a column or table identifier and no as a value.

Other simpler workaround is to use single quotes:

SELECT * FROM Orders WHERE OrderDate = '01-01-98'
or
SET QUOTED_IDENTIFIER ON
SELECT * FROM Orders WHERE OrderDate = '01-01-98'

Further, single quotes can be escaped with a previous single quote. So supposing that default SET QUOTED_IDENTIFIER is ON, this is ok for selecting using La maison d''Asie value:

SELECT * FROM Territories WHERE ShipName = 'La maison d''Asie'

Comments:

Add your comment:

Gender:
(Too weird, even outrageous perhaps?: try a regeneration)
Top of the page