Not getting correct answer while converting from h

2019-08-28 01:27发布

I have the statements:

declare @x varchar(10)
declare @cardnum bigint
set @cardNum=9999999999
set @x=convert(varchar, CONVERT (varbinary(8), CONVERT(BIGINT, @cardNum)))
print @x

I an getting the answer as Tãÿ not getting Hex value 2540BE3FF as string

1条回答
劳资没心,怎么记你
2楼-- · 2019-08-28 02:07

Try it like this:

declare @x varchar(50)
declare @cardnum bigint
set @cardNum=9999999999

declare @hexbin varbinary(max)
set @hexbin = CONVERT (varbinary(8), @cardNum)

Set @x = CONVERT(varchar(max), @hexbin, 1)
print @x

Set @x = CONVERT(varchar(max), @hexbin, 2)
print @x

Read more about it on this MSDN link

查看更多
登录 后发表回答