Home >> FAQs/Tutorials >> SQL Server FAQ

SQL Server FAQ - Using Binary Strings in Arithmetical Operations

By: FYIcenter.com

(Continued from previous topic...)

Can Binary Strings Be Used in Arithmetical Operations?

Can 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

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.

(Continued on next topic...)

  1. How To Concatenate Two Character Strings Together?
  2. What Happens When Unicode Strings Concatenate with Non-Unicode Strings?
  3. How To Convert a Unicode Strings to Non-Unicode Strings?
  4. What Are the Character String Functions Supported by SQL Server 2005?
  5. How To Insert New Line Characters into Strings?
  6. How To Locate and Take Substrings with CHARINDEX() and SUBSTRING() Functions?
  7. How To Concatenate Two Binary Strings Together?
  8. Can Binary Strings Be Used in Arithmetical Operations?
  9. How To Convert Binary Strings into Integers?
  10. Can Binary Strings Be Converted into NUMERIC or FLOAT Data Types?
  11. Can Binary Strings Be Converted into Character Strings?
  12. Can Binary Strings Be Converted into Unicode Character Strings?
  13. How To Convert Binary Strings into Hexadecimal Character Strings
  14. What Are Bitwise Operations?

Related Articles:

More...


Other Tutorials/FAQs:

More...


Related Resources:

More...


Selected Jobs:

More...