How To Concatenate Two Binary Strings Together?
Submitted by: AdministratorSQL Server 2005 allows to concatenate two binary strings into a single string with the (+) operator. The following tutorial exercise shows you some binary string concatenation examples:
-- Concatenating two binary string literals
SELECT 0x57656C636F6D6520746F20
+ 0x46594963656E7465722E636F6D;
GO
0x57656C636F6D6520746F2046594963656E7465722E636F6D
-- Watch out: This is not a binary string concatenation
SELECT '0x57656C636F6D6520746F20'
+ '0x46594963656E7465722E636F6D';
GO
0x57656C636F6D6520746F200x46594963656E7465722E636F6D
-- Concatenating two binary strings
SELECT CONVERT(VARBINARY(40),'Welcome to ')
+ CONVERT(VARBINARY(40),'GlobalGuideLine.com');
GO
0x57656C636F6D6520746F2046594963656E7465722E636F6D
-- Binary strings can not be concatenated
with character strings
SELECT 'Welcome to '
+ 0x46594963656E7465722E636F6D;
GO
Msg 402, Level 16, State 1, Line 1
The data types varchar and varbinary are incompatible
in the add operator.
Submitted by: Administrator
-- Concatenating two binary string literals
SELECT 0x57656C636F6D6520746F20
+ 0x46594963656E7465722E636F6D;
GO
0x57656C636F6D6520746F2046594963656E7465722E636F6D
-- Watch out: This is not a binary string concatenation
SELECT '0x57656C636F6D6520746F20'
+ '0x46594963656E7465722E636F6D';
GO
0x57656C636F6D6520746F200x46594963656E7465722E636F6D
-- Concatenating two binary strings
SELECT CONVERT(VARBINARY(40),'Welcome to ')
+ CONVERT(VARBINARY(40),'GlobalGuideLine.com');
GO
0x57656C636F6D6520746F2046594963656E7465722E636F6D
-- Binary strings can not be concatenated
with character strings
SELECT 'Welcome to '
+ 0x46594963656E7465722E636F6D;
GO
Msg 402, Level 16, State 1, Line 1
The data types varchar and varbinary are incompatible
in the add operator.
Submitted by: Administrator
Read Online MS SQL Server Job Interview Questions And Answers
Top MS SQL Server Questions
☺ | How To Select Some Specific Rows from a Table in MS SQL Server? |
☺ | How To Sort Query Output in Descending Order in MS SQL Server? |
☺ | How to download and install the scaled-down database AdventureWorksLT? |
☺ | How To Find Out What Is the Default Collation in a Database? |
☺ | How To Write Character String Constants or Literals in MS SQL Server? |
Top Databases Programming Categories
☺ | RDBMS Interview Questions. |
☺ | SQL Interview Questions. |
☺ | SSRS Interview Questions. |
☺ | Sybase Interview Questions. |
☺ | Database Administrator (DBA) Interview Questions. |