Single-byte String Literals in SQL Server Transact-SQL

Q

What are single-byte string literals supported in SQL Server Transact-SQL?

✍: FYIcenter.com

A

Single-byte string literals in Transact-SQL are sequences of characters enclosed in single quotes.

String literals are used to provide values to string variables or table columns like CHAR(40), VARCHAR(40), etc.

String literals are also used in string operations in expressions and string arguments in functions.

Here are some simple rules on how to write string literals:

  • String literals must be enclosed in single quotes like '...'.
  • An empty string must be expressed as ''.
  • A single quote inside the string must be entered twice like 'Murphy''s law'.
  • Each character in a string is represented in a single byte.
  • Character strings use non-default character code pages must use the COLLATE clause to provide the code page through a collate name. For example, 'Français' COLLATE French_CI_AS.

Here are some example on how to write string literals:

PRINT 'FYIcenter.com';
PRINT 'Murphy''s law';
PRINT '2017-11-31';

PRINT 'Hello '+'Joe!';

DECLARE @var CHAR(16);
SET @var = 'Hello World!';
PRINT @var;

 

Data Literals in SQL Server Transact-SQL

⇒⇒SQL Server Transact-SQL Tutorials

2017-05-20, 367👍, 0💬