SQLTeam.com | Weblogs | Forums

Varbinary to list of integers


I am trying to get a list of integers '60,61,62,67,68,69,70,73,100,105' from a value stored into the database '0x0000000000000070780200001002'.

Someone suggested that I should first try to convert the value above into a bit array and then try to read one byte at a time- but this does not make any sense. Can you please help?

this script:

DECLARE @tbl table (VarCharVal varchar(500), VarBinaryVal varbinary(1000));
        (VarCharVal, VarBinaryVal)
        ('60,61,62,67,68,69,70,73,100,105', Cast('60,61,62,67,68,69,70,73,100,105' AS varbinary(1000)));
SELECT t.VarCharVal
     , t.VarBinaryVal
     , Cast(t.VarBinaryVal AS varchar(500)) CastVarBin
FROM @tbl t;

Produces this:


Thank you so much for the prompt answer, but I don't have the list of integers to pack them into varbinary. All I have is, e.g., '0x0000000000000060780200001002' (this is already in the database produced by c# code) and I want to have a list of integers '60,61,62,67,68,69,70,73,100,105'

The varbinary value 0x0000000000000060780200001002 does not have the string of integers. Is it encrypted?

Yes, the list I gave somehow packed into that varbinary field.

In first post you write varbinary value 0x0000000000000070780200001002 should be integer array values 60,61,62,67,68,69,70,73,100,105

In second post varbinary value is 0x0000000000000060780200001002 for the same integer array values as in first post.

That doesn't make sence.

Also you write that the varbinary value is produced by c# code. Do you happen to have the c# source code? Otherwise this seems like an impossible task.