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
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