可以在sql server中将varchar(32)(十六进制字符串,如0x81f2cf442269e111b99c1cc1deedf59c)转换为bigint吗?将varchar(32)转换为bigint
我已经试过这样:
select convert(bigint, convert (varbinary(16), '0x81f2cf442269e111b99c1cc1deedf59c', 1))
,但我不知道,它的作品具有更高和更低的数值。
可以在sql server中将varchar(32)(十六进制字符串,如0x81f2cf442269e111b99c1cc1deedf59c)转换为bigint吗?将varchar(32)转换为bigint
我已经试过这样:
select convert(bigint, convert (varbinary(16), '0x81f2cf442269e111b99c1cc1deedf59c', 1))
,但我不知道,它的作品具有更高和更低的数值。
是可能的一个varchar(32)(十六进制字符串等 0x81f2cf442269e111b99c1cc1deedf59c)转换为SQL Server中的BIGINT?
2个答案与范例。两者根本错误。
不能做。任何人都在意第一次运行基本的数学检查?
32十六进制= 16字节。 比特:8字节。
你所有的代码是一回事 - 没用。你不能将16字节的32位十六进制字符串转换为8字节的数字。仅在极少数情况下(高8字节全0)。
我希望你能用下面的方式去,请你试试这个。
DECLARE @HexValue Varchar(32)
SET @HexValue = '0x81f2cf442269e111b99c1cc1deedf59c'
Declare @Query NVARCHAR(100)
Declare @Parameters NVARCHAR(50)
Declare @ReturnValue BIGINT
SET @Query = N'Select @Result = Convert(BIGINT,' + @HexValue + ')'
SET @Parameters = N'@Result BIGINT output'
EXEC MASTER.dbo.Sp_executesql @Query, @Parameters, @ReturnValue OUTPUT
SELECT @ReturnValue
感谢您的时间。
为什么你需要这样的东西? – 2012-03-28 09:10:54
将此字符串存储在bigint列中 – malinois 2012-03-28 09:11:47
我认为这些帖子可能会帮助您http://blog.sqlauthority.com/2010/02/01/sql-server-question-how-to-convert-hex-to-decimal /和http://dpatrickcaldwell.blogspot.com/2009/05/converting-hexadecimal-or-binary-to.html – 2012-03-28 09:16:09