Can Binary Strings Be Converted into NUMERIC or FLOAT Data Types?
Submitted by: AdministratorCan binary strings be converted into numeric or float data types? The answer is no. Binary strings can not be converted implicitly or explicitly into NUMERIC, DECIMAL, REAL, or FLOAT data types. The tutorial exercise gives you some examples of errors when converting binary strings to NUMERIC or FLOAT data types:
-- Implicit conversion to NUMERIC
SELECT 0x66 + 0.44;
GO
Msg 8114, Level 16, State 5, Line 1
Error converting data type varbinary to numeric.
-- Explicit conversion to NUMERIC
SELECT CONVERT(NUMERIC(9,2), 0x66) + 0.44;
GO
Msg 8114, Level 16, State 5, Line 1
Error converting data type varbinary to numeric.
-- Implicit conversion to REAL
DECLARE @real REAL;
SET @real = 0x66;
Msg 206, Level 16, State 2, Line 2
Operand type clash: varbinary is incompatible with real
-- Implicit conversion to FLOAT
DECLARE @float FLOAT(53);
SET @float = 0x66;
Msg 206, Level 16, State 2, Line 2
Operand type clash: varbinary is incompatible with float
Submitted by: Administrator
-- Implicit conversion to NUMERIC
SELECT 0x66 + 0.44;
GO
Msg 8114, Level 16, State 5, Line 1
Error converting data type varbinary to numeric.
-- Explicit conversion to NUMERIC
SELECT CONVERT(NUMERIC(9,2), 0x66) + 0.44;
GO
Msg 8114, Level 16, State 5, Line 1
Error converting data type varbinary to numeric.
-- Implicit conversion to REAL
DECLARE @real REAL;
SET @real = 0x66;
Msg 206, Level 16, State 2, Line 2
Operand type clash: varbinary is incompatible with real
-- Implicit conversion to FLOAT
DECLARE @float FLOAT(53);
SET @float = 0x66;
Msg 206, Level 16, State 2, Line 2
Operand type clash: varbinary is incompatible with float
Submitted by: Administrator
Read Online MS SQL Server Job Interview Questions And Answers
Top MS SQL Server Questions
☺ | Does Index Slows Down INSERT Statements? |
☺ | 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? |
☺ | What Happens If Strings Are Casted into Wrong Code Pages in MS SQL Server? |
☺ | How To Use Subqueries with the IN Operators in MS SQL Server? |
Top Databases Programming Categories
☺ | RDBMS Interview Questions. |
☺ | SQL Interview Questions. |
☺ | SSRS Interview Questions. |
☺ | Database Administrator (DBA) Interview Questions. |
☺ | Sybase Interview Questions. |