1

I have a table that has a varbinary field like:

0x83838383838372723 .....

I would like to concatenate this varbinary field to a string, for example:

SELECT CONCAT('Varbinary value is', varbinary_field)
FROM MyTable

I expect the following string:

Varbinary value is 0x83838383838372723

I need to use concat so how to do it?

1
  • 3
    Er... This is tagged as SQL 2008 but CONCAT was introduced in 2012. Also, I believe you're looking for CONVERT(VARCHAR(MAX), myBinaryValue, 1) or something like that. See binary styles here Commented Dec 20, 2016 at 21:21

2 Answers 2

2

You might use the built-in function fn_varbintohexstr:

DECLARE @SomeHexString VARBINARY(MAX)=CAST('This is just some text, which should be a HEX-string' AS VARBINARY(MAX));
SELECT @SomeHexString;

SELECT 'This is concatenated: ' + sys.fn_varbintohexstr(@SomeHexString)

This function existed in 2005 already, but was limited in length. Should be fine with your 2008 environment...

Sign up to request clarification or add additional context in comments.

Comments

-1

Something like this should work. BTW, it seems the varbinary you posted is not really valid.

declare @Bin varbinary(max) = convert(varbinary(max), 'My binary value')

select concat('varbinary value is: ', cast(@Bin as varchar(max)))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.