INF: QUOTED_IDENTIFIER and Strings with Single Quotation MarksID: Q156501
|
SQL Server 6.0 introduced support for the ANSI SQL rules regarding the use of single and double quotation marks. This article describes how to process single and double quotation marks in an ANSI environment.
Starting with SQL Server 6.0, you can use SET QUOTED_IDENTIFIER ON to have
SQL Server start enforcing the ANSI SQL rules regarding quotation marks.
According to the ANSI rules, double quotation marks are reserved for
delimiting identifiers (such as database, table, or column names), while
single quotation marks are reserved for delimiting character strings being
used as data. For example, consider the following statement:
select * from "authors" where "au_lname" = 'White'
select * from authors where au_lname = 'O''Brien'
UCHAR *szCol1[41]="";
SDWORD pcbVal1 = SQL_NTS;
SQLPrepare(hstmt,
(UCHAR *)"select * from authors where au_lname = ?", SQL_NTS);
SQLBindParameter(hstmt1,
1,
SQL_PARAM_INPUT,
SQL_C_CHAR,
SQL_CHAR,
40,
0,
szCol1,
sizeof(szCol1),
&pcbVal1);
strcpy(szCol1, "O'Brien");
SQLExecute(hstmt1);
Additional query words: embedded
Keywords : kbusage SSrvGen
Version : 2.5 6.0
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: April 2, 1999