有没有办法将sys.fn_varbintohexstr结果转回varbinary? [英] Is there a way to turn sys.fn_varbintohexstr result back to varbinary?

查看:232
本文介绍了有没有办法将sys.fn_varbintohexstr结果转回varbinary?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQL Server中是否有function可以做到这一点? 反转sys.fn_varbintohexstr?

Is there a function in SQL Server to do that? to reverse sys.fn_varbintohexstr?

推荐答案

您需要在动态SQL语句中使用十六进制字符串,以便将其解析为varbinary.这是如何执行此操作的一个示例.

You need to use the hexadecimal character string in a dynamic SQL statement, so that it will be parsed as a varbinary. Here's one example of how to do that.

-- Our original and fn_varbintohexstr values:
DECLARE @original varbinary(max) = 0xd0cf11;
DECLARE @sql nvarchar(max) = N'SET @converted = ' + sys.fn_varbintohexstr(@original) + ';';

-- Do the conversion
DECLARE @converted varbinary(max);
EXEC sp_executesql @sql,
   N'@converted varbinary(max) OUTPUT',
   @converted = @converted OUTPUT;

-- Proof it worked
PRINT @original;
PRINT @converted;
PRINT CASE WHEN @original = @converted THEN 'Same' ELSE 'Different' END;

这将打印Same.

如果尝试使用user1617237的版本,将会看到为什么它不是正确的答案.

If you try user1617237's version, you'll see why it is not a correct answer.

这篇关于有没有办法将sys.fn_varbintohexstr结果转回varbinary?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆