Can Binary Strings Be Used in Arithmetical Operations?
Submitted by: AdministratorCan binary strings be used in arithmetical operations? The answer is yes. But there are two simple rules you need to remember:
* If an arithmetical operation has one binary string operand and one integer data type operand, the binary string operand will be converted to a integer data type to match the other operand. The operation will be performed as an integer operation.
* A + operator with two binary strings will be performed as binary string concatenation.
* A -, *, or / operator with two binary strings will be performed as binary string concatenation.
The tutorial exercise below shows you some good examples:
SELECT 0x66 + 44
GO
146
SELECT 0x66 - 44
GO
58
SELECT 0x66 * 44
GO
4488
SELECT 0x66 / 44
GO
2
SELECT 0x66 + 0x44
GO
0x6644
Submitted by: Administrator
* If an arithmetical operation has one binary string operand and one integer data type operand, the binary string operand will be converted to a integer data type to match the other operand. The operation will be performed as an integer operation.
* A + operator with two binary strings will be performed as binary string concatenation.
* A -, *, or / operator with two binary strings will be performed as binary string concatenation.
The tutorial exercise below shows you some good examples:
SELECT 0x66 + 44
GO
146
SELECT 0x66 - 44
GO
58
SELECT 0x66 * 44
GO
4488
SELECT 0x66 / 44
GO
2
SELECT 0x66 + 0x44
GO
0x6644
Submitted by: Administrator
SELECT 0x66 - 0x44
GO
Msg 8117, Level 16, State 1, Line 1
Operand data type varbinary is invalid
for subtract operator.
SELECT 0x66 * 0x44
GO
Msg 8117, Level 16, State 1, Line 1
Operand data type varbinary is invalid
for multiply operator.
SELECT 0x66 / 0x44
GO
Msg 8117, Level 16, State 1, Line 1
Operand data type varbinary is invalid
for divide operator.
Submitted by: Administrator
GO
Msg 8117, Level 16, State 1, Line 1
Operand data type varbinary is invalid
for subtract operator.
SELECT 0x66 * 0x44
GO
Msg 8117, Level 16, State 1, Line 1
Operand data type varbinary is invalid
for multiply operator.
SELECT 0x66 / 0x44
GO
Msg 8117, Level 16, State 1, Line 1
Operand data type varbinary is invalid
for divide operator.
Submitted by: Administrator
Read Online MS SQL Server Job Interview Questions And Answers
Top MS SQL Server Questions
☺ | What Happens If You Insert a Duplicate Key for the Primary Key Column in MS SQL Server? |
☺ | How To Execute the Cursor Queries with "OPEN" Statements? |
☺ | What Happens If Strings Are Casted into Wrong Code Pages in MS SQL Server? |
☺ | How To Convert a Numeric Expression from One Data Type to Another? |
☺ | PHP MSSQL - How To Display a Past Time in Days, Hours and Minutes? |
Top Databases Programming Categories
☺ | RDBMS Interview Questions. |
☺ | SQL Interview Questions. |
☺ | SSRS Interview Questions. |
☺ | Database Administrator (DBA) Interview Questions. |
☺ | Sybase Interview Questions. |