SQL Server Quotations and Datatypes
Using Literal Values
The following table indicates whether quotes are needed for each of the SQL Server datatypes:
Datatype | Quotes needed for literal values |
Binary | No |
Bit | No |
Char(n) | Yes |
Datetime | Yes |
Decimal(p[,s]) | No |
Float(n) | No |
Image | No |
Int | No |
Money | No |
Nchar | Yes |
Ntext | Yes |
Numeric | No |
Nvarchar | Yes |
Real | No |
Smalldatetime | Yes |
Smallint | No |
Smallmoney | No |
Text | Yes |
Timestamp | No |
Tinyint | No |
Uniqueidentifier | Yes if string, No if hexadecimal |
Varbinary | No |
Varchar(n) | No |
Single versus double quotations
Microsoft recommends using single quotation marks for literal values, but you should know that you can, if desired, use double quotes by issuing the following Transact-SQL statement first:
SET QUOTED_IDENTIFIER OFF
Once you issue this Transact-SQL statement, you can use double quotes for the entire lifetime of your database connection. You do not have to issue this Transact-SQL statement before every statement that uses double quotes.