Binary Literals in SQL Server Transact-SQL

Q

What are binary literals supported in SQL Server Transact-SQL?

✍: FYIcenter.com

A

Binary literals in Transact-SQL are sequences of bytes written in hexadecimal digits with 0x prefixes.

Binary literals are used to provide values to binary variables or table columns like BINARY, VARBINARY, IMAGE, etc.

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

  • A binary literal must be written in hexadecimal digits.
  • A binary literal must be prefixed with 0x.

Here are some example on how to write exact numeric literals:

PRINT 0xff;
PRINT 0x00ff;
PRINT 0x00ff00;

DECLARE @var BINARY(4);
SET @var = 0x41424344;
PRINT @var;

 

Entering Binary String Literals in SQL Server Transact-SQL

Approximate Numeric Literals in SQL Server Transact-SQL

Data Literals in SQL Server Transact-SQL

⇑⇑ SQL Server Transact-SQL Tutorials

2017-05-05, 10048🔥, 0💬